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

Create and populate OIDC blob store for the cluster #3564

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

rajdeepc2792
Copy link
Collaborator

@rajdeepc2792 rajdeepc2792 commented May 7, 2024

Which issue this PR addresses:

Jira issue :- ARO-4373
Related Docs:-
https://msazure.visualstudio.com/AzureRedHatOpenShift/_wiki/wikis/AzureRedHatOpenShift.wiki/603739/OIDC-Traffic-Flow
Similar Implementation:-
https://gitlab.cee.redhat.com/service/uhc-clusters-service/-/tree/master/pkg/aws/cloudcredentialbuilder

What this PR does / why we need it:

  • The RP needs to generate a keypair
  • The private key needs to be stored in cosmos, It needs to be encrypted if it's stored in cosmos
  • The private key will be passed to the installer-aro-wrapper via a secret as part of the existing cluster document in CosmosDB(Not implemented here)
  • Set / populate OIDC issuerURL in the internal API
  • The RP should generate OIDC docs
  • Should populate them in regional storage accounts
  • The OIDC doc needs to be resolvable through the regional AFD instances and should follow a hashing pattern

Test plan for issue:

  • Unit Tests
  • CI
  • CI e2e
  • Local cluster installation
  • INT Deployment / e2e

Is there any documentation that needs to be updated for this PR?

  • Doc for setting up the full RP. (Part of the PR)

How do you know this will function as expected in production?

Testing the implementation in all the environments.

@rajdeepc2792 rajdeepc2792 added work-in-progress chainsaw Pull requests or issues owned by Team Chainsaw labels May 7, 2024
@rajdeepc2792 rajdeepc2792 force-pushed the rajdeepc2792/ARO-4373 branch 2 times, most recently from 58d9129 to 1b8076a Compare May 7, 2024 17:01
@rajdeepc2792
Copy link
Collaborator Author

/azp run ci,e2e

Copy link

Azure Pipelines successfully started running 2 pipeline(s).

Copy link
Collaborator

@cadenmarchese cadenmarchese left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not a full review, just a few questions as you're working through the draft and testing. looks great!

pkg/util/storage/manager.go Outdated Show resolved Hide resolved
pkg/util/storage/manager.go Outdated Show resolved Hide resolved
@github-actions github-actions bot added the needs-rebase branch needs a rebase label May 7, 2024
Copy link

github-actions bot commented May 7, 2024

Please rebase pull request.

@rajdeepc2792
Copy link
Collaborator Author

/azp run e2e

Copy link

Pull request contains merge conflicts.

@github-actions github-actions bot removed the needs-rebase branch needs a rebase label May 8, 2024
@rajdeepc2792 rajdeepc2792 added the hold Hold label May 8, 2024
pkg/api/openshiftcluster.go Show resolved Hide resolved
ResourceGroupID string `json:"resourceGroupId,omitempty"`
FipsValidatedModules FipsValidatedModules `json:"fipsValidatedModules,omitempty"`
OIDCIssuer OIDCIssuer `json:"oidcIssuer,omitempty"`
BoundServiceAccountSigningKey SecureString `json:"boundServiceAccountSigningKey,omitempty"`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we're not going to populate this on older clusters, correct? So this field should only be set on WI clusters?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this value will only be generated and populated for MIWI clusters as part of OIDC blob creations for the clusters.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to make it a pointer then?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed it SecureBytes now.

pkg/cluster/deploybaseresources.go Show resolved Hide resolved
pkg/cluster/install.go Show resolved Hide resolved
pkg/env/env.go Show resolved Hide resolved
pkg/frontend/asyncoperationresult_get.go Outdated Show resolved Hide resolved
)

func CreateKeyPair() (encPrivateKey []byte, encPublicKey []byte, err error) {
bitSize := 4096
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this the bit size & recommendation of OpenShift for SA private keys?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creation of jwks is mostly copied from Cloud-credential-operator same as ROSA STS

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also - would it be possible to have the cloud credential operator folks publish functions for generating key pairs, so that way ROSA and ARO can consume those directly instead of repeating the same code?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@niontive they do actually: https://github.com/openshift/cloud-credential-operator/blob/master/docs/ccoctl.md#creating-rsa-keys-1 It's a CLI tool though, it's a bit different for us since we own the OIDC stuff.

@github-actions github-actions bot added the needs-rebase branch needs a rebase label May 13, 2024
Copy link

Please rebase pull request.

@github-actions github-actions bot removed the needs-rebase branch needs a rebase label May 28, 2024
pkg/api/openshiftcluster.go Show resolved Hide resolved
pkg/cluster/install.go Show resolved Hide resolved
pkg/cluster/deploybaseresources.go Outdated Show resolved Hide resolved
@rajdeepc2792 rajdeepc2792 force-pushed the rajdeepc2792/ARO-4373 branch 4 times, most recently from d684aeb to a067322 Compare May 31, 2024 21:20
@rajdeepc2792 rajdeepc2792 marked this pull request as ready for review May 31, 2024 21:20
@rajdeepc2792
Copy link
Collaborator Author

/azp run ci

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

pkg/cluster/delete.go Outdated Show resolved Hide resolved
@@ -261,6 +273,19 @@ func (p *prod) ACRDomain() string {
return p.acrDomain
}

func (p *prod) OIDCStorageAccountName() string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My main concern is we'll have to maintain the storage account name in two separate places. Ex: https://msazure.visualstudio.com/AzureRedHatOpenShift/_git/ARO-Pipelines?path=/rp/oidc/Region/Templates/modules/storage.bicep

Would you be good if we:

  • Define the storage account names in rp-config
  • Have ARO-Pipelines and ARO-RP consume that name from rp-config

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Nic for raising this, I agree and back your idea for the consistency. It was hard anyways to get the container naming using the assumption present in the function.
Although I would like to get the consensus on the this.
cc: @cadenmarchese

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per discussion, this is going to be handle as a separate issue after the PR is merged. I will post the Jira story for the same here when created.

"fmt"

"github.com/pkg/errors"
"gopkg.in/square/go-jose.v2"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like Square deprecated this and it's maintained here now: https://github.com/go-jose/go-jose/blob/main/go.mod

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoided the direct dependency on square but the github.com/coreos/go-oidc still uses it indirectly.

@rajdeepc2792
Copy link
Collaborator Author

/azp run e2e

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@rajdeepc2792 rajdeepc2792 self-assigned this Jun 4, 2024
@@ -169,6 +176,11 @@ func New(ctx context.Context, log *logrus.Entry, _env env.Interface, db database
return nil, err
}

rpBlob, err := azblob.NewManager(_env, _env.SubscriptionID(), msiCredential)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why pass sub & _env if they're both part of env?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed it to rpBlob, err := azblob.NewManager(_env.Environment(), _env.SubscriptionID(), msiCredential)
Haven't passed _env directly as there can be a use case where different SubscriptionID is needed.

pkg/cluster/deploybaseresources.go Show resolved Hide resolved
Copy link

github-actions bot commented Jun 6, 2024

Please rebase pull request.

@github-actions github-actions bot added needs-rebase branch needs a rebase and removed ready-for-review labels Jun 6, 2024
@github-actions github-actions bot removed the needs-rebase branch needs a rebase label Jun 6, 2024
@rajdeepc2792
Copy link
Collaborator Author

/azp run ci,e2e

Copy link

Azure Pipelines successfully started running 2 pipeline(s).

Copy link
Contributor

@kimorris27 kimorris27 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! I just made some small suggestions here and there.

blobContainerName := env.OIDCBlobContainerPrefix + m.doc.ID

publicAccess := azstorage.PublicAccessNone
// Public access on OIDC Container needed for development environments because of no AFD avaialbility
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super nitpicky: avaialbility -> availability

if !bloberror.HasCode(err, bloberror.ContainerNotFound) {
return err
}
needToCreateBlobContainer = true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can simplify this by removing needToCreateBlobContainer and returning nil on this line.

"github.com/Azure/ARO-RP/pkg/util/azureclient"
)

type BlobContainersClient interface {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this being used? I couldn't find any references to it. Could it be removed?

@@ -1394,3 +1399,214 @@ func TestNewPublicLoadBalancer(t *testing.T) {
})
}
}

func TestCreateOIDC(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could consider adding two more test cases:

  • Fail to create OIDCBuilder
  • OIDCBuilder fails to populate OIDC blob

Bytes: x509.MarshalPKCS1PrivateKey(privateKey),
})

// Generate public key from private keypair
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would reword this comment for clarity's sake. IIUC what's happening here is that the keypair has already been generated and you are simply putting the public key data into a byte array.

Suggested change
// Generate public key from private keypair
// Serialize public key into a byte array to prepare to store it in the OIDC storage blob

// Generate public key from private keypair
pubKeyBytes, err := x509.MarshalPKIXPublicKey(&privateKey.PublicKey)
if err != nil {
return nil, nil, errors.Wrapf(err, "failed to generate public key from private")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return nil, nil, errors.Wrapf(err, "failed to generate public key from private")
return nil, nil, errors.Wrapf(err, "failed to serialize public key")

See my comment a few lines above this for the reasoning behind this suggestion.

// Copyright (c) Microsoft Corporation.
// Licensed under the Apache License 2.0.

func TestEnsureOIDCDocs(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could consider adding a few more test cases here to cover some other ways in which the code could fail:

  • Public key is not of type RSA (the default case in the switch)
  • Failed to fetch key ID from public key
  • JSON encoding of web key set failed (if you can - I'm not sure if you can easily test this)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chainsaw Pull requests or issues owned by Team Chainsaw
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants