Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SECURESIGN-570] Rekor add options to set trillian_log_server #196

Merged
merged 1 commit into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions api/v1alpha1/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@ type MonitoringConfig struct {
Enabled bool `json:"enabled"`
}

// TrillianService configuration to connect Trillian server
type TrillianService struct {
// Address to Trillian Log Server End point
//+optional
Address string `json:"address,omitempty"`
// Port of Trillian Log Server End point
//+kubebuilder:validation:Minimum:=1
//+kubebuilder:validation:Maximum:=65535
//+kubebuilder:default:=8091
//+optional
Port *int32 `json:"port,omitempty"`
}

// LocalObjectReference contains enough information to let you locate the
// referenced object inside the same namespace.
// +structType=atomic
Expand Down
3 changes: 3 additions & 0 deletions api/v1alpha1/rekor_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ type RekorSpec struct {
// If it is unset, the operator will create new Merkle tree in the Trillian backend
//+optional
TreeID *int64 `json:"treeID,omitempty"`
// Trillian service configuration
//+kubebuilder:default:={port: 8091}
Trillian TrillianService `json:"trillian,omitempty"`
// Define whether you want to export service or not
ExternalAccess ExternalAccess `json:"externalAccess,omitempty"`
//Enable Service monitors for rekor
Expand Down
10 changes: 9 additions & 1 deletion api/v1alpha1/rekor_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ var _ = Describe("Rekor", func() {
It("outputs the CR", func() {
storage := k8sresource.MustParse("987Gi")
tree := int64(1269875)
port := int32(8091)

rekorInstance = Rekor{
ObjectMeta: metav1.ObjectMeta{
Name: "rekor-full-manifest",
Expand Down Expand Up @@ -240,6 +242,10 @@ var _ = Describe("Rekor", func() {
Key: "key",
},
},
Trillian: TrillianService{
Address: "trillian-system.default.svc",
Port: &port,
},
},
}

Expand All @@ -253,7 +259,6 @@ var _ = Describe("Rekor", func() {
When("CR is partially set", func() {

It("sets spec.pvc.storage if spec.pvc is partially set", func() {

rekorInstance = Rekor{
ObjectMeta: metav1.ObjectMeta{
Name: "rekor-storage",
Expand Down Expand Up @@ -299,6 +304,9 @@ func generateRekorObject(name string) *Rekor {
Retain: utils.Pointer(true),
Size: &storage,
},
Trillian: TrillianService{
Port: utils.Pointer(int32(8091)),
},
},
}
}
21 changes: 21 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions bundle/manifests/rhtas-operator.clusterserviceversion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ metadata:
]
capabilities: Seamless Upgrades
containerImage: registry.redhat.io/rhtas/rhtas-rhel9-operator@sha256:a21f7128694a64989bf0d84a7a7da4c1ffc89edf62d594dc8bea7bcfe9ac08d3
createdAt: "2024-06-12T14:09:20Z"
createdAt: "2024-06-13T10:31:51Z"
features.operators.openshift.io/cnf: "false"
features.operators.openshift.io/cni: "false"
features.operators.openshift.io/csi: "false"
Expand All @@ -204,7 +204,7 @@ metadata:
features.operators.openshift.io/token-auth-azure: "false"
features.operators.openshift.io/token-auth-gcp: "false"
operators.openshift.io/valid-subscription: '["Red Hat Trusted Artifact Signer"]'
operators.operatorframework.io/builder: operator-sdk-v1.34.1
operators.operatorframework.io/builder: operator-sdk-v1.34.2
operators.operatorframework.io/project_layout: go.kubebuilder.io/v4
repository: https://github.com/securesign/secure-sign-operator
support: Red Hat
Expand Down
16 changes: 16 additions & 0 deletions bundle/manifests/rhtas.redhat.com_rekors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,22 @@ spec:
If it is unset, the operator will create new Merkle tree in the Trillian backend
format: int64
type: integer
trillian:
default:
port: 8091
description: Trillian service configuration
properties:
address:
description: Address to Trillian Log Server End point
type: string
port:
default: 8091
description: Port of Trillian Log Server End point
format: int32
maximum: 65535
minimum: 1
type: integer
type: object
type: object
status:
description: RekorStatus defines the observed state of Rekor
Expand Down
16 changes: 16 additions & 0 deletions bundle/manifests/rhtas.redhat.com_securesigns.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,22 @@ spec:
If it is unset, the operator will create new Merkle tree in the Trillian backend
format: int64
type: integer
trillian:
default:
port: 8091
description: Trillian service configuration
properties:
address:
description: Address to Trillian Log Server End point
type: string
port:
default: 8091
description: Port of Trillian Log Server End point
format: int32
maximum: 65535
minimum: 1
type: integer
type: object
type: object
trillian:
description: TrillianSpec defines the desired state of Trillian
Expand Down
16 changes: 16 additions & 0 deletions config/crd/bases/rhtas.redhat.com_rekors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,22 @@ spec:
If it is unset, the operator will create new Merkle tree in the Trillian backend
format: int64
type: integer
trillian:
default:
port: 8091
description: Trillian service configuration
properties:
address:
description: Address to Trillian Log Server End point
type: string
port:
default: 8091
description: Port of Trillian Log Server End point
format: int32
maximum: 65535
minimum: 1
type: integer
type: object
type: object
status:
description: RekorStatus defines the observed state of Rekor
Expand Down
16 changes: 16 additions & 0 deletions config/crd/bases/rhtas.redhat.com_securesigns.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,22 @@ spec:
If it is unset, the operator will create new Merkle tree in the Trillian backend
format: int64
type: integer
trillian:
default:
port: 8091
description: Trillian service configuration
properties:
address:
description: Address to Trillian Log Server End point
type: string
port:
default: 8091
description: Port of Trillian Log Server End point
format: int32
maximum: 65535
minimum: 1
type: integer
type: object
type: object
trillian:
description: TrillianSpec defines the desired state of Trillian
Expand Down
48 changes: 0 additions & 48 deletions internal/controller/rekor/actions/pending.go

This file was deleted.

21 changes: 15 additions & 6 deletions internal/controller/rekor/actions/server/createTree.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import (
"context"
"fmt"

"github.com/google/trillian"
rhtasv1alpha1 "github.com/securesign/operator/api/v1alpha1"
"github.com/securesign/operator/internal/controller/common"
"github.com/securesign/operator/internal/controller/common/action"
k8sutils "github.com/securesign/operator/internal/controller/common/utils/kubernetes"
"github.com/securesign/operator/internal/controller/constants"
"github.com/securesign/operator/internal/controller/rekor/actions"
trillian "github.com/securesign/operator/internal/controller/trillian/actions"
"github.com/securesign/operator/internal/controller/rekor/utils"
actions2 "github.com/securesign/operator/internal/controller/trillian/actions"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -39,12 +40,20 @@ func (i createTrillianTreeAction) Handle(ctx context.Context, instance *rhtasv1a
return i.StatusUpdate(ctx, instance)
}
var err error
var tree *trillian.Tree
var trillUrl string

trillUrl, err := k8sutils.GetInternalUrl(ctx, i.Client, instance.Namespace, trillian.LogserverDeploymentName)
if err != nil {
return i.Failed(err)
switch {
case instance.Spec.Trillian.Port == nil:
err = fmt.Errorf("%s: %w", i.Name(), utils.TrillianPortNotSpecified)
case instance.Spec.Trillian.Address == "":
trillUrl = fmt.Sprintf("%s.%s.svc:%d", actions2.LogserverDeploymentName, instance.Namespace, *instance.Spec.Trillian.Port)
default:
trillUrl = fmt.Sprintf("%s:%d", instance.Spec.Trillian.Address, *instance.Spec.Trillian.Port)
}
tree, err := common.CreateTrillianTree(ctx, "rekor-tree", trillUrl+":8091", constants.CreateTreeDeadline)
i.Logger.V(1).Info("trillian logserver", "address", trillUrl)

tree, err = common.CreateTrillianTree(ctx, "rekor-tree", trillUrl, constants.CreateTreeDeadline)
if err != nil {
meta.SetStatusCondition(&instance.Status.Conditions, metav1.Condition{
Type: actions.ServerCondition,
Expand Down
10 changes: 9 additions & 1 deletion internal/controller/rekor/actions/server/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/securesign/operator/internal/controller/constants"
"github.com/securesign/operator/internal/controller/rekor/actions"
"github.com/securesign/operator/internal/controller/rekor/utils"
actions2 "github.com/securesign/operator/internal/controller/trillian/actions"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
Expand Down Expand Up @@ -38,7 +39,14 @@ func (i deployAction) Handle(ctx context.Context, instance *rhtasv1alpha1.Rekor)
updated bool
)
labels := constants.LabelsFor(actions.ServerComponentName, actions.ServerDeploymentName, instance.Name)
dp, err := utils.CreateRekorDeployment(instance, actions.ServerDeploymentName, actions.RBACName, labels)

insCopy := instance.DeepCopy()
if insCopy.Spec.Trillian.Address == "" {
insCopy.Spec.Trillian.Address = fmt.Sprintf("%s.%s.svc", actions2.LogserverDeploymentName, instance.Namespace)
}
i.Logger.V(1).Info("trillian logserver", "address", insCopy.Spec.Trillian.Address)
dp, err := utils.CreateRekorDeployment(insCopy, actions.ServerDeploymentName, actions.RBACName, labels)

if err != nil {
meta.SetStatusCondition(&instance.Status.Conditions, metav1.Condition{
Type: actions.ServerCondition,
Expand Down
2 changes: 0 additions & 2 deletions internal/controller/rekor/rekor_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ func (r *RekorReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl
// NONE -> PENDING
actions2.NewInitializeConditions(),

// PENDING
actions2.NewPendingAction(),
// PENDING -> CREATE
server.NewGenerateSignerAction(),

Expand Down
11 changes: 0 additions & 11 deletions internal/controller/rekor/rekor_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@ import (
"github.com/securesign/operator/internal/controller/common/utils"

"github.com/securesign/operator/api/v1alpha1"
"github.com/securesign/operator/internal/controller/common/utils/kubernetes"
"github.com/securesign/operator/internal/controller/constants"
"github.com/securesign/operator/internal/controller/rekor/actions"
"github.com/securesign/operator/internal/controller/rekor/actions/server"
trillian "github.com/securesign/operator/internal/controller/trillian/actions"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -128,15 +126,6 @@ var _ = Describe("Rekor controller", func() {
return meta.IsStatusConditionPresentAndEqual(found.Status.Conditions, constants.Ready, metav1.ConditionFalse)
}).Should(BeTrue())

Eventually(func() string {
found := &v1alpha1.Rekor{}
Expect(k8sClient.Get(ctx, typeNamespaceName, found)).Should(Succeed())
return meta.FindStatusCondition(found.Status.Conditions, constants.Ready).Reason
}).Should(Equal(constants.Pending))

By("Move to CreatingPhase by creating trillian service")
Expect(k8sClient.Create(ctx, kubernetes.CreateService(Namespace, trillian.LogserverDeploymentName, 8091, constants.LabelsForComponent(trillian.LogServerComponentName, instance.Name)))).To(Succeed())

By("Rekor signer created")
found := &v1alpha1.Rekor{}
Eventually(func() *v1alpha1.SecretKeySelector {
Expand Down
11 changes: 11 additions & 0 deletions internal/controller/rekor/utils/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package utils

import "errors"

var (
ServerConfigNotSpecified = errors.New("server config name not specified")
TreeNotSpecified = errors.New("tree not specified")
TrillianAddressNotSpecified = errors.New("trillian address not specified")
TrillianPortNotSpecified = errors.New("trillian port not specified")
SignerKeyNotSpecified = errors.New("signer key reference not specified")
)
Loading
Loading