Skip to content

Commit 2af8eec

Browse files
tommyd450osmman
authored andcommitted
Enabling Rekor to set custom Trillian log signer service
1 parent b0e9150 commit 2af8eec

17 files changed

+152
-82
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/ctlog/actions/handle_keys.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func (g handleKeys) Handle(ctx context.Context, instance *v1alpha1.CTlog) *actio
100100
}
101101
}
102102
config, err = utils.GeneratePublicKey(&utils.PrivateKeyConfig{PrivateKey: private, PrivateKeyPass: password})
103-
if err != nil || config == nil{
103+
if err != nil || config == nil {
104104
return g.Failed(fmt.Errorf("unable to generate public key: %w", err))
105105
}
106106
data = map[string][]byte{"public": config.PublicKey}

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+
default:
51+
trillUrl = fmt.Sprintf("%s:%d", instance.Spec.Trillian.Address, *instance.Spec.Trillian.Port)
4652
}
47-
tree, err := common.CreateTrillianTree(ctx, "rekor-tree", trillUrl+":8091")
53+
i.Logger.V(1).Info("trillian logserver", "address", trillUrl)
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/rekor_controller_test.go

-11
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,9 @@ import (
2323
"github.com/securesign/operator/controllers/common/utils"
2424

2525
"github.com/securesign/operator/api/v1alpha1"
26-
"github.com/securesign/operator/controllers/common/utils/kubernetes"
2726
"github.com/securesign/operator/controllers/constants"
2827
"github.com/securesign/operator/controllers/rekor/actions"
2928
"github.com/securesign/operator/controllers/rekor/actions/server"
30-
trillian "github.com/securesign/operator/controllers/trillian/actions"
3129
appsv1 "k8s.io/api/apps/v1"
3230
corev1 "k8s.io/api/core/v1"
3331
"k8s.io/apimachinery/pkg/api/errors"
@@ -128,15 +126,6 @@ var _ = Describe("Rekor controller", func() {
128126
return meta.IsStatusConditionPresentAndEqual(found.Status.Conditions, constants.Ready, metav1.ConditionFalse)
129127
}, time.Minute, time.Second).Should(BeTrue())
130128

131-
Eventually(func() string {
132-
found := &v1alpha1.Rekor{}
133-
Expect(k8sClient.Get(ctx, typeNamespaceName, found)).Should(Succeed())
134-
return meta.FindStatusCondition(found.Status.Conditions, constants.Ready).Reason
135-
}, time.Minute, time.Second).Should(Equal(constants.Pending))
136-
137-
By("Move to CreatingPhase by creating trillian service")
138-
Expect(k8sClient.Create(ctx, kubernetes.CreateService(Namespace, trillian.LogserverDeploymentName, 8091, constants.LabelsForComponent(trillian.LogServerComponentName, instance.Name)))).To(Succeed())
139-
140129
By("Rekor signer created")
141130
found := &v1alpha1.Rekor{}
142131
Eventually(func() *v1alpha1.SecretKeySelector {

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+
)

0 commit comments

Comments
 (0)