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

CCO-318: Enable Azure Workload Identity authentication. #906

Merged
merged 3 commits into from Jun 6, 2023

Conversation

jstuever
Copy link
Contributor

@jstuever jstuever commented Apr 5, 2023

Authenticate with an Azure Workload Identity (AZWI) serviceaccount token when client secret is absent from auth config.

https://issues.redhat.com/browse/CCO-318

@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 5, 2023
@jstuever jstuever force-pushed the CCO-318 branch 3 times, most recently from 8c1e78d to 97d0dbd Compare April 11, 2023 21:31
@jstuever jstuever changed the title WIP: Enable Azure Workload Identity authentication. WIP: CCO-318: Enable Azure Workload Identity authentication. Apr 19, 2023
@openshift-ci-robot
Copy link
Contributor

openshift-ci-robot commented Apr 19, 2023

@jstuever: This pull request references CCO-318 which is a valid jira issue.

In response to this:

Authenticate with an Azure Workload Identity (AZWI) serviceaccount token when client secret is absent from auth config.

WIP TODO:

https://issues.redhat.com/browse/CCO-318

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Apr 19, 2023
pkg/operator/operator.go Outdated Show resolved Hide resolved
@openshift-ci-robot
Copy link
Contributor

openshift-ci-robot commented May 1, 2023

@jstuever: This pull request references CCO-318 which is a valid jira issue.

In response to this:

Authenticate with an Azure Workload Identity (AZWI) serviceaccount token when client secret is absent from auth config.

WIP TODO:

https://issues.redhat.com/browse/CCO-318

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@openshift-ci-robot
Copy link
Contributor

openshift-ci-robot commented May 1, 2023

@jstuever: This pull request references CCO-318 which is a valid jira issue.

In response to this:

Authenticate with an Azure Workload Identity (AZWI) serviceaccount token when client secret is absent from auth config.

WIP TODO:

https://issues.redhat.com/browse/CCO-318

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 5, 2023
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 9, 2023
@openshift-ci-robot
Copy link
Contributor

openshift-ci-robot commented May 9, 2023

@jstuever: This pull request references CCO-318 which is a valid jira issue.

In response to this:

Authenticate with an Azure Workload Identity (AZWI) serviceaccount token when client secret is absent from auth config.

https://issues.redhat.com/browse/CCO-318

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@jstuever jstuever changed the title WIP: CCO-318: Enable Azure Workload Identity authentication. CCO-318: Enable Azure Workload Identity authentication. May 9, 2023
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label May 9, 2023
Copy link
Contributor

@Miciah Miciah left a comment

Choose a reason for hiding this comment

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

I've made some minor suggestions, but this looks fine to me overall.
/approve

Comment on lines 72 to 94
var (
cred azcore.TokenCredential
err error
)
if config.AzureWorkloadIdentityEnabled && strings.TrimSpace(config.ClientSecret) == "" {
options := azidentity.WorkloadIdentityCredentialOptions{
ClientOptions: azcore.ClientOptions{
Cloud: cloudConfig,
},
ClientID: config.ClientID,
TenantID: config.TenantID,
TokenFilePath: config.FederatedTokenFile,
}
cred, err = azidentity.NewWorkloadIdentityCredential(&options)
if err != nil {
return nil, err
}
} else {
options := azidentity.ClientSecretCredentialOptions{
ClientOptions: azcore.ClientOptions{
Cloud: cloudConfig,
},
}
cred, err = azidentity.NewClientSecretCredential(config.TenantID, config.ClientID, config.ClientSecret, &options)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason to declare err in the outer scope?

Suggested change
var (
cred azcore.TokenCredential
err error
)
if config.AzureWorkloadIdentityEnabled && strings.TrimSpace(config.ClientSecret) == "" {
options := azidentity.WorkloadIdentityCredentialOptions{
ClientOptions: azcore.ClientOptions{
Cloud: cloudConfig,
},
ClientID: config.ClientID,
TenantID: config.TenantID,
TokenFilePath: config.FederatedTokenFile,
}
cred, err = azidentity.NewWorkloadIdentityCredential(&options)
if err != nil {
return nil, err
}
} else {
options := azidentity.ClientSecretCredentialOptions{
ClientOptions: azcore.ClientOptions{
Cloud: cloudConfig,
},
}
cred, err = azidentity.NewClientSecretCredential(config.TenantID, config.ClientID, config.ClientSecret, &options)
var cred azcore.TokenCredential
if config.AzureWorkloadIdentityEnabled && strings.TrimSpace(config.ClientSecret) == "" {
options := azidentity.WorkloadIdentityCredentialOptions{
ClientOptions: azcore.ClientOptions{
Cloud: cloudConfig,
},
ClientID: config.ClientID,
TenantID: config.TenantID,
TokenFilePath: config.FederatedTokenFile,
}
var err error
cred, err = azidentity.NewWorkloadIdentityCredential(&options)
if err != nil {
return nil, err
}
} else {
options := azidentity.ClientSecretCredentialOptions{
ClientOptions: azcore.ClientOptions{
Cloud: cloudConfig,
},
}
var err error
cred, err = azidentity.NewClientSecretCredential(config.TenantID, config.ClientID, config.ClientSecret, &options)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No reason, was just blindly following the enhancement.
Updated.

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 Author

Choose a reason for hiding this comment

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

No, I did not. I must have fumbled it during a rebase. Fixed. Thanks!

Comment on lines 18 to 38
Environment azure.Environment
SubscriptionID string
ClientID string
ClientSecret string
FederatedTokenFile string
TenantID string
AzureWorkloadIdentityEnabled bool
Copy link
Contributor

Choose a reason for hiding this comment

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

Would you mind adding godoc for these fields? In particular, it's getting confusing which fields are used in what situations. Looks like SubscriptionID, ClientID, and TenantID are always required; FederatedTokenFile is required when using workload identity; and ClientSecret is required when not using workload identity. Is that correct? Following is my attempt at describing these fields—please check for errors and discard or modify as necessary:

Suggested change
Environment azure.Environment
SubscriptionID string
ClientID string
ClientSecret string
FederatedTokenFile string
TenantID string
AzureWorkloadIdentityEnabled bool
// Environment describes the Azure environment: ChinaCloud,
// USGovernmentCloud, PublicCloud, or AzureStackCloud. If empty,
// AzureStackCloud is assumed.
Environment azure.Environment
// SubscriptionID is the subscription id for the Azure identity.
SubscriptionID string
// ClientID is an Azure application client id.
ClientID string
// ClientSecret is an Azure application client secret. It is required
// if Azure workload identity is not used.
ClientSecret string
// FederatedTokenFile is the path to a file containing a workload
// identity token. If FederatedTokenFile is specified and
// AzureWorkloadIdentityEnabled is true, then Azure workload identity is
// used instead of using a client secret.
FederatedTokenFile string
// TenantID is the Azure tenant ID.
TenantID string
// AzureWorkloadIdentityEnabled indicates whether the
// "AzureWorkloadIdentity" feature gate is enabled.
AzureWorkloadIdentityEnabled bool

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, and thanks!

Comment on lines 130 to 131
// example of future featuregate read and usage to set a variable to pass to a controller
AzureWorkloadIdentityEnabled := featureGates.Enabled(configv1.FeatureGateAzureWorkloadIdentity)
Copy link
Contributor

Choose a reason for hiding this comment

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

The comment can be removed (I missed that 3d26626 removed the _ = sets.New[configv1.FeatureGateName](enabled...).Has("AzureWorkloadIdentity") line that the comment described). Uppercase AzureWorkloadIdentityEnabled looks funny for a function-local variable.

Suggested change
// example of future featuregate read and usage to set a variable to pass to a controller
AzureWorkloadIdentityEnabled := featureGates.Enabled(configv1.FeatureGateAzureWorkloadIdentity)
azureWorkloadIdentityEnabled := featureGates.Enabled(configv1.FeatureGateAzureWorkloadIdentity)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@openshift-ci
Copy link
Contributor

openshift-ci bot commented May 15, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Miciah

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 15, 2023
@jstuever jstuever requested a review from Miciah May 16, 2023 22:42
@candita
Copy link
Contributor

candita commented May 17, 2023

/retest-required

@jstuever
Copy link
Contributor Author

/retest

1 similar comment
@jstuever
Copy link
Contributor Author

/retest

@ahardin-rh
Copy link

/label docs-approved

@openshift-ci openshift-ci bot added the docs-approved Signifies that Docs has signed off on this PR label May 26, 2023
@lihongan
Copy link
Contributor

/label qe-approved

@openshift-ci openshift-ci bot added the qe-approved Signifies that QE has signed off on this PR label May 29, 2023
@davemulford
Copy link

Adding px-approved per a conversation with cfields.

/label px-approved

@openshift-ci openshift-ci bot added the px-approved Signifies that Product Support has signed off on this PR label May 30, 2023
Authenticate with an Azure Workload Identity (AZWI) serviceaccount token
when client secret is absent from auth config.
@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. label Jun 1, 2023
@jstuever
Copy link
Contributor Author

jstuever commented Jun 1, 2023

Rebased to resolve merge conflicts in go.mod and related module files.

@Miciah
Copy link
Contributor

Miciah commented Jun 1, 2023

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jun 1, 2023
@jstuever
Copy link
Contributor Author

jstuever commented Jun 1, 2023

/retest

@Miciah
Copy link
Contributor

Miciah commented Jun 1, 2023

/hold
#939 is top priority; make sure it merges first.

@openshift-ci openshift-ci bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 1, 2023
@Miciah
Copy link
Contributor

Miciah commented Jun 2, 2023

/hold cancel
and
/test all
now that #939 has merged.

@openshift-ci openshift-ci bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 2, 2023
@Miciah
Copy link
Contributor

Miciah commented Jun 2, 2023

e2e-gcp-operator failed because TestInternalLoadBalancerGlobalAccessGCP and TestInternalLoadBalancer failed. This is a known issue (OCPBUGS-13106), unrelated to the changes in this PR.
/override ci/prow/e2e-gcp-operator

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Jun 2, 2023

@Miciah: Overrode contexts on behalf of Miciah: ci/prow/e2e-gcp-operator

In response to this:

e2e-gcp-operator failed because TestInternalLoadBalancerGlobalAccessGCP and TestInternalLoadBalancer failed. This is a known issue (OCPBUGS-13106), unrelated to the changes in this PR.
/override ci/prow/e2e-gcp-operator

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Jun 2, 2023

@jstuever: all tests passed!

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@dgoodwin
Copy link
Contributor

dgoodwin commented Jun 6, 2023

/label jira/valid-bug

@openshift-ci openshift-ci bot added the jira/valid-bug Indicates that a referenced Jira bug is valid for the branch this PR is targeting. label Jun 6, 2023
@openshift-merge-robot openshift-merge-robot merged commit e068d04 into openshift:master Jun 6, 2023
14 checks passed
@jstuever jstuever deleted the CCO-318 branch July 7, 2023 18:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. docs-approved Signifies that Docs has signed off on this PR jira/valid-bug Indicates that a referenced Jira bug is valid for the branch this PR is targeting. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. lgtm Indicates that a PR is ready to be merged. px-approved Signifies that Product Support has signed off on this PR qe-approved Signifies that QE has signed off on this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants