Skip to content

Commit

Permalink
Merge pull request #679 from securesign/make-sure-operator-can-run-lo…
Browse files Browse the repository at this point in the history
…cally

fix: Resolving rekor pub key locally against openshift
  • Loading branch information
osmman authored Oct 23, 2024
2 parents cf329cd + bf2fccc commit 80e5d05
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 12 additions & 1 deletion internal/controller/rekor/actions/server/resolve_pub_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/klog/v2"
"k8s.io/utils/ptr"
)

Expand Down Expand Up @@ -127,9 +128,19 @@ func (i resolvePubKeyAction) resolvePubKey(instance rhtasv1alpha1.Rekor) ([]byte
var (
data []byte
err error
url = fmt.Sprintf("http://%s.%s.svc", actions.ServerDeploymentName, instance.Namespace)
)

if data, err = i.requestPublicKey(fmt.Sprintf("http://%s.%s.svc", actions.ServerDeploymentName, instance.Namespace)); err == nil {
inContainer, err := k8sutils.ContainerMode()
if err == nil {
if !inContainer && instance.Status.Url != "" {
url = instance.Status.Url
}
} else {
klog.Info("Can't recognise operator mode - expecting in-container run")
}

if data, err = i.requestPublicKey(url); err == nil {
return data, nil
}
i.Logger.Info("retrying to get rekor public key")
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/rekor/rekor_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ var _ = Describe("Rekor controller", func() {
Expect(err).To(Succeed())

httpmock.SetMockTransport(http.DefaultClient, map[string]httpmock.RoundTripFunc{
"http://rekor-server.default.svc/api/v1/log/publicKey": func(req *http.Request) *http.Response {
"http://rekor.local/api/v1/log/publicKey": func(req *http.Request) *http.Response {
return &http.Response{
StatusCode: http.StatusOK,
Body: io.NopCloser(bytes.NewReader(pubKeyData)),
Expand Down

0 comments on commit 80e5d05

Please sign in to comment.