Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 3a44319

Browse files
tommyd450osmman
authored andcommittedJun 3, 2024·
Enabling Rekor to set custom Trillian log signer service
1 parent b0e9150 commit 3a44319

15 files changed

+151
-70
lines changed
 

‎api/v1alpha1/common.go

+13
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,19 @@ type MonitoringConfig struct {
2121
Enabled bool `json:"enabled"`
2222
}
2323

24+
// TrillianService configuration to connect Trillian server
25+
type TrillianService struct {
26+
// Address to Trillian Log Server End point
27+
//+optional
28+
Address string `json:"address,omitempty"`
29+
// Port of Trillian Log Server End point
30+
//+kubebuilder:validation:Minimum:=1
31+
//+kubebuilder:validation:Maximum:=65535
32+
//+kubebuilder:default:=8091
33+
//+optional
34+
Port *int32 `json:"port,omitempty"`
35+
}
36+
2437
// LocalObjectReference contains enough information to let you locate the
2538
// referenced object inside the same namespace.
2639
// +structType=atomic

‎api/v1alpha1/rekor_types.go

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ type RekorSpec struct {
1313
// If it is unset, the operator will create new Merkle tree in the Trillian backend
1414
//+optional
1515
TreeID *int64 `json:"treeID,omitempty"`
16+
// Trillian service configuration
17+
Trillian TrillianService `json:"trillian,omitempty"`
1618
// Define whether you want to export service or not
1719
ExternalAccess ExternalAccess `json:"externalAccess,omitempty"`
1820
//Enable Service monitors for rekor

‎api/v1alpha1/rekor_types_test.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ var _ = Describe("Rekor", func() {
198198
It("outputs the CR", func() {
199199
storage := k8sresource.MustParse("987Gi")
200200
tree := int64(1269875)
201+
port := int32(8091)
201202

202203
rekorInstance = Rekor{
203204
ObjectMeta: metav1.ObjectMeta{
@@ -241,6 +242,10 @@ var _ = Describe("Rekor", func() {
241242
Key: "key",
242243
},
243244
},
245+
Trillian: TrillianService{
246+
Address: "trillian-system.default.svc",
247+
Port: &port,
248+
},
244249
},
245250
}
246251

@@ -254,7 +259,6 @@ var _ = Describe("Rekor", func() {
254259
When("CR is partially set", func() {
255260

256261
It("sets spec.pvc.storage if spec.pvc is partially set", func() {
257-
258262
rekorInstance = Rekor{
259263
ObjectMeta: metav1.ObjectMeta{
260264
Name: "rekor-storage",
@@ -300,6 +304,9 @@ func generateRekorObject(name string) *Rekor {
300304
Retain: utils.Pointer(true),
301305
Size: &storage,
302306
},
307+
Trillian: TrillianService{
308+
Port: utils.Pointer(int32(8091)),
309+
},
303310
},
304311
}
305312
}

‎api/v1alpha1/zz_generated.deepcopy.go

+21
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎bundle/manifests/rhtas-operator.clusterserviceversion.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ metadata:
192192
]
193193
capabilities: Seamless Upgrades
194194
containerImage: registry.redhat.io/rhtas/rhtas-rhel9-operator@sha256:a21f7128694a64989bf0d84a7a7da4c1ffc89edf62d594dc8bea7bcfe9ac08d3
195-
createdAt: "2024-05-28T11:15:21Z"
195+
createdAt: "2024-06-03T14:37:13Z"
196196
features.operators.openshift.io/cnf: "false"
197197
features.operators.openshift.io/cni: "false"
198198
features.operators.openshift.io/csi: "false"
@@ -204,7 +204,7 @@ metadata:
204204
features.operators.openshift.io/token-auth-azure: "false"
205205
features.operators.openshift.io/token-auth-gcp: "false"
206206
operators.openshift.io/valid-subscription: '["Red Hat Trusted Artifact Signer"]'
207-
operators.operatorframework.io/builder: operator-sdk-v1.34.1
207+
operators.operatorframework.io/builder: operator-sdk-v1.34.2
208208
operators.operatorframework.io/project_layout: go.kubebuilder.io/v3
209209
repository: https://github.com/securesign/secure-sign-operator
210210
support: Red Hat

‎bundle/manifests/rhtas.redhat.com_rekors.yaml

+14
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,20 @@ spec:
204204
If it is unset, the operator will create new Merkle tree in the Trillian backend
205205
format: int64
206206
type: integer
207+
trillian:
208+
description: Trillian service configuration
209+
properties:
210+
address:
211+
description: Address to Trillian Log Server End point
212+
type: string
213+
port:
214+
default: 8091
215+
description: Port of Trillian Log Server End point
216+
format: int32
217+
maximum: 65535
218+
minimum: 1
219+
type: integer
220+
type: object
207221
type: object
208222
status:
209223
description: RekorStatus defines the observed state of Rekor

‎bundle/manifests/rhtas.redhat.com_securesigns.yaml

+14
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,20 @@ spec:
551551
If it is unset, the operator will create new Merkle tree in the Trillian backend
552552
format: int64
553553
type: integer
554+
trillian:
555+
description: Trillian service configuration
556+
properties:
557+
address:
558+
description: Address to Trillian Log Server End point
559+
type: string
560+
port:
561+
default: 8091
562+
description: Port of Trillian Log Server End point
563+
format: int32
564+
maximum: 65535
565+
minimum: 1
566+
type: integer
567+
type: object
554568
type: object
555569
trillian:
556570
description: TrillianSpec defines the desired state of Trillian

‎config/crd/bases/rhtas.redhat.com_rekors.yaml

+14
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,20 @@ spec:
204204
If it is unset, the operator will create new Merkle tree in the Trillian backend
205205
format: int64
206206
type: integer
207+
trillian:
208+
description: Trillian service configuration
209+
properties:
210+
address:
211+
description: Address to Trillian Log Server End point
212+
type: string
213+
port:
214+
default: 8091
215+
description: Port of Trillian Log Server End point
216+
format: int32
217+
maximum: 65535
218+
minimum: 1
219+
type: integer
220+
type: object
207221
type: object
208222
status:
209223
description: RekorStatus defines the observed state of Rekor

‎config/crd/bases/rhtas.redhat.com_securesigns.yaml

+14
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,20 @@ spec:
551551
If it is unset, the operator will create new Merkle tree in the Trillian backend
552552
format: int64
553553
type: integer
554+
trillian:
555+
description: Trillian service configuration
556+
properties:
557+
address:
558+
description: Address to Trillian Log Server End point
559+
type: string
560+
port:
561+
default: 8091
562+
description: Port of Trillian Log Server End point
563+
format: int32
564+
maximum: 65535
565+
minimum: 1
566+
type: integer
567+
type: object
554568
type: object
555569
trillian:
556570
description: TrillianSpec defines the desired state of Trillian

‎controllers/rekor/actions/pending.go

-48
This file was deleted.

‎controllers/rekor/actions/server/createTree.go

+15-7
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ package server
33
import (
44
"context"
55
"fmt"
6-
6+
"github.com/google/trillian"
77
rhtasv1alpha1 "github.com/securesign/operator/api/v1alpha1"
88
"github.com/securesign/operator/controllers/common"
99
"github.com/securesign/operator/controllers/common/action"
10-
k8sutils "github.com/securesign/operator/controllers/common/utils/kubernetes"
1110
"github.com/securesign/operator/controllers/constants"
1211
"github.com/securesign/operator/controllers/rekor/actions"
13-
trillian "github.com/securesign/operator/controllers/trillian/actions"
12+
"github.com/securesign/operator/controllers/rekor/utils"
13+
actions2 "github.com/securesign/operator/controllers/trillian/actions"
1414
v1 "k8s.io/api/core/v1"
1515
"k8s.io/apimachinery/pkg/api/meta"
1616
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -39,12 +39,20 @@ func (i createTrillianTreeAction) Handle(ctx context.Context, instance *rhtasv1a
3939
return i.StatusUpdate(ctx, instance)
4040
}
4141
var err error
42+
var tree *trillian.Tree
43+
var trillUrl string
4244

43-
trillUrl, err := k8sutils.GetInternalUrl(ctx, i.Client, instance.Namespace, trillian.LogserverDeploymentName)
44-
if err != nil {
45-
return i.Failed(err)
45+
switch {
46+
case instance.Spec.Trillian.Port == nil:
47+
err = fmt.Errorf("%s: %w", i.Name(), utils.TrillianPortNotSpecified)
48+
case instance.Spec.Trillian.Address == "":
49+
trillUrl = fmt.Sprintf("%s.%s.svc:%d", actions2.LogserverDeploymentName ,instance.Namespace, instance.Spec.Trillian.Port)
50+
i.Logger.V(1).Info("trillian logserver", "address", trillUrl)
51+
default:
52+
trillUrl = fmt.Sprintf("%s:%d", instance.Spec.Trillian.Address, instance.Spec.Trillian.Port)
4653
}
47-
tree, err := common.CreateTrillianTree(ctx, "rekor-tree", trillUrl+":8091")
54+
55+
tree, err = common.CreateTrillianTree(ctx, "rekor-tree", trillUrl)
4856
if err != nil {
4957
meta.SetStatusCondition(&instance.Status.Conditions, metav1.Condition{
5058
Type: actions.ServerCondition,

‎controllers/rekor/actions/server/deployment.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package server
33
import (
44
"context"
55
"fmt"
6+
actions2 "github.com/securesign/operator/controllers/trillian/actions"
67

78
"github.com/securesign/operator/controllers/common/action"
89
"github.com/securesign/operator/controllers/constants"
@@ -38,7 +39,14 @@ func (i deployAction) Handle(ctx context.Context, instance *rhtasv1alpha1.Rekor)
3839
updated bool
3940
)
4041
labels := constants.LabelsFor(actions.ServerComponentName, actions.ServerDeploymentName, instance.Name)
41-
dp, err := utils.CreateRekorDeployment(instance, actions.ServerDeploymentName, actions.RBACName, labels)
42+
43+
insCopy := instance.DeepCopy()
44+
if insCopy.Spec.Trillian.Address == "" {
45+
insCopy.Spec.Trillian.Address = fmt.Sprintf("%s.%s.svc", actions2.LogserverDeploymentName, instance.Namespace)
46+
}
47+
i.Logger.V(1).Info("trillian logserver", "address", insCopy.Spec.Trillian.Address)
48+
dp, err := utils.CreateRekorDeployment(insCopy, actions.ServerDeploymentName, actions.RBACName, labels)
49+
4250
if err != nil {
4351
meta.SetStatusCondition(&instance.Status.Conditions, metav1.Condition{
4452
Type: actions.ServerCondition,

‎controllers/rekor/rekor_controller.go

-2
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,6 @@ func (r *RekorReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl
9090
// NONE -> PENDING
9191
actions2.NewInitializeConditions(),
9292

93-
// PENDING
94-
actions2.NewPendingAction(),
9593
// PENDING -> CREATE
9694
server.NewGenerateSignerAction(),
9795

‎controllers/rekor/utils/errors.go

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package utils
2+
3+
import "errors"
4+
5+
var (
6+
ServerConfigNotSpecified = errors.New("server config name not specified")
7+
TreeNotSpecified = errors.New("tree not specified")
8+
TrillianAddressNotSpecified = errors.New("trillian address not specified")
9+
TrillianPortNotSpecified = errors.New("trillian port not specified")
10+
SignerKeyNotSpecified = errors.New("signer key reference not specified")
11+
)

‎controllers/rekor/utils/rekor_deployment.go

+14-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package utils
22

33
import (
4-
"errors"
54
"fmt"
65

76
"github.com/securesign/operator/api/v1alpha1"
@@ -12,17 +11,23 @@ import (
1211
)
1312

1413
func CreateRekorDeployment(instance *v1alpha1.Rekor, dpName string, sa string, labels map[string]string) (*apps.Deployment, error) {
15-
if instance.Status.ServerConfigRef == nil {
16-
return nil, errors.New("server config name not specified")
17-
}
18-
if instance.Status.TreeID == nil {
19-
return nil, errors.New("reference to trillian TreeID not set")
14+
switch {
15+
case instance.Status.ServerConfigRef == nil:
16+
return nil, fmt.Errorf("CreateRekorDeployment: %w", ServerConfigNotSpecified)
17+
case instance.Status.TreeID == nil:
18+
return nil, fmt.Errorf("CreateRekorDeployment: %w", TreeNotSpecified)
19+
case instance.Spec.Trillian.Address == "":
20+
return nil, fmt.Errorf("CreateRekorDeployment: %w", TrillianAddressNotSpecified)
21+
case instance.Spec.Trillian.Port == nil:
22+
return nil, fmt.Errorf("CreateRekorDeployment: %w", TrillianPortNotSpecified)
2023
}
24+
2125
env := make([]core.EnvVar, 0)
26+
2227
appArgs := []string{
2328
"serve",
24-
"--trillian_log_server.address=trillian-logserver." + instance.Namespace + ".svc",
25-
"--trillian_log_server.port=8091",
29+
"--trillian_log_server.address=" + instance.Spec.Trillian.Address,
30+
fmt.Sprintf("--trillian_log_server.port=%d", *instance.Spec.Trillian.Port),
2631
"--trillian_log_server.sharding_config=/sharding/sharding-config.yaml",
2732
"--redis_server.address=rekor-redis",
2833
"--redis_server.port=6379",
@@ -71,7 +76,7 @@ func CreateRekorDeployment(instance *v1alpha1.Rekor, dpName string, sa string, l
7176
// KMS secret
7277
if instance.Spec.Signer.KMS == "secret" || instance.Spec.Signer.KMS == "" {
7378
if instance.Status.Signer.KeyRef == nil {
74-
return nil, errors.New("signer key ref not specified")
79+
return nil, SignerKeyNotSpecified
7580
}
7681
svsPrivate := &core.SecretVolumeSource{
7782
SecretName: instance.Status.Signer.KeyRef.Name,

0 commit comments

Comments
 (0)