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

docs: Azure authentication refactoring design #1940

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

shahramk64
Copy link
Contributor

@shahramk64 shahramk64 commented Nov 20, 2024

Description

What this PR does / why we need it:

This PR proposes a design doc for refactoring Azure authentication modules in Ratify. It describes the existing Azure authentication modules and it's pain points and provide a solution to refactor the code to solve those pain points.

Which issue(s) this PR fixes (optional, using fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when the PR gets merged):

Provide a design doc to #1944

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Helm Chart Change (any edit/addition/update that is necessary for changes merged to the main branch)
  • This change requires a documentation update

Checklist:

  • Does the affected code have corresponding tests?
  • Are the changes documented, not just with inline documentation, but also with conceptual documentation such as an overview of a new feature, or task-based documentation like a tutorial? Consider if this change should be announced on your project blog.
  • Does this introduce breaking changes that would require an announcement or bumping the major version?
  • Do all new files have appropriate license header?

Post Merge Requirements

  • MAINTAINERS: manually trigger the "Publish Package" workflow after merging any PR that indicates Helm Chart Change

Signed-off-by: Shahram Kalantari <[email protected]>
@shahramk64 shahramk64 force-pushed the skalantari/refactor-azure-authentication-design-doc branch from d1f0005 to e8a9fae Compare November 20, 2024 07:16
2. **Infer authentication type** automatically based on the environment, reducing user configuration overhead.
3. **Unify implementations** for workload identity and managed identity in ORAS auth providers.
4. Implement a **chained authentication process**:
- Workload Identity → Managed Identity → Azure CLI.
Copy link
Collaborator

Choose a reason for hiding this comment

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

In terms of Azure CLI, does that mean Ratify CLI will also support auth to Azure?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, one of the goals of this work is to support Azure authentication in the CLI scenario and the azidentity SDK seems to be able to facilitate this through a number of credential types like AzureCLICredential, AzureDeveloperCLICredential, DefaultAzureCredential, and ChainedTokenCredential.
ChainedTokenCredential seems to be the right choice for ratify to consolidate all scenarios in one single place.

@shahramk64 shahramk64 changed the title Azure authentication refactoring design Docs: Azure authentication refactoring design Nov 20, 2024
@shahramk64 shahramk64 changed the title Docs: Azure authentication refactoring design docs: Azure authentication refactoring design Nov 20, 2024

### **Goals**
1. Design a **common package** for Azure authentication logic.
2. **Infer authentication type** automatically based on the environment, reducing user configuration overhead.
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is a great add for almost all scenarios but there are scenarios where an override from the uesr to specify exactly the cred type might be required. Notation CLI encountered this too. We should consider exposing override capability which will not use the chained credential.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good point. As you suggested, we can provide this ability by accepting the override from user input.

}
```
#### **2. Refactor ORAS Auth Providers**
- Combine `azureidentity.go` and `azureworkloadidentity.go` into a single file.
Copy link
Collaborator

Choose a reason for hiding this comment

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

How will maintain backwards compatability and ensure no breaking changes? We'll need to ensure we can support existing workload identity managed identity providers when user specifies.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we can ensure this by providing the override ability, as you pointed above.

}
```
#### **2. Refactor ORAS Auth Providers**
- Combine `azureidentity.go` and `azureworkloadidentity.go` into a single file.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this mean we will introduce a new auth provider or just refactor existing one and add new fields necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we can combine the existing two Oras auth providers into one auth provider. If chained authentication is used, there is no need to have both. We can override the chained credential process based on the user input, to explicitly use workload or managed identity.

- Authentication type will be inferred based on environment variables.

#### **3. Refactor Key Management and Certificate Providers**
- Update the providers to leverage the new `pkg/common/cloudauthproviders/azure` package for authentication.
Copy link
Collaborator

Choose a reason for hiding this comment

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

From a user perspective, will there be any change in how the credentials are configured? Is KMP AKV setup with client id etc. decoupled still from ORAS azure auth providers?

Copy link
Contributor Author

@shahramk64 shahramk64 Nov 20, 2024

Choose a reason for hiding this comment

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

Good point. This requires more thinking. There are a few alternatives here:
1- Decoupled scenario: both can provide their own configurations. I wonder how the chained credential should work in this case. For example if both are defining a client id variable, which one is set in the ENV variable that the chained credential uses.
2- Coupled scenario: the configuration that is common to both is extracted and placed into a separate resource to represent both. This means that both will use the same credential type and the same credential config, (unless overridden explicitly?)
I think a decision needs to be made whether to support different types of credentials for Oras and KMP at the same time or not (for example, workload identity for KMP and managed identity for Oras), and also when using the same credential type for both, to support different identities for them (for example, a different client id for Oras and KMP)

@shahramk64 shahramk64 marked this pull request as ready for review November 20, 2024 23:03

---

### **Proposed Tasks**
Copy link
Collaborator

Choose a reason for hiding this comment

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

If we plan to deprecate any existing auth provider/config, we should add this to the V2 tracking issue that @binbin-li made.

- Consolidated authentication logic minimizes duplication and enhances clarity.

2. **Enhanced User Experience**:
- Automatic detection of authentication type eliminates the need for explicit configuration in most environments.
Copy link
Collaborator

@FeynmanZhou FeynmanZhou Nov 21, 2024

Choose a reason for hiding this comment

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

Could you please elaborate on which auth configuration will be simplified after refactoring? Will Ratify detect whether users use a Azure Workload Identity or Azure Managed Identity? Maybe we could reference this doc to clarify which configuration could be removed https://ratify.dev/docs/quickstarts/ratify-on-azure#create-a-custom-resource-for-accessing-acr

Signed-off-by: Shahram Kalantari <[email protected]>
Copy link

codecov bot commented Dec 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

@susanshi
Copy link
Collaborator

Ready for review, maintainers please take another look @binbin-li , @akashsinghal , @susanshi

3. Ability to provide required parameters: When using the default azure credential option, we can only rely on the environment variables, meaning that we cannot provide the client_id, tenant_id, or any other parameter explicitly. This is particularly problematic when Ratify is provided with multiple auth providers. With the chanined token credentials, each credential type in the chain can be provided with the required parameters explicitly if needed.

#### **2. Refactor ORAS Auth Providers**
- Combine `azureidentity.go` and `azureworkloadidentity.go` into a single file.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since we are keeping the existing authProviders, and introducing new azure auth provider. Should we just keep current implementation as is ( reduce risk , and introduce a new implementation/new file for the new auth provider. This is simliar to how we deprecated CertProvider and introduce KMP CR.

Copy link
Collaborator

Choose a reason for hiding this comment

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

+1

# **Azure Authentication Refactoring in Ratify**

## **Introduction**
Authentication is a critical process in Ratify, ensuring secure access to artifatcs in container registries, and to keys, secrets and certificates from cloud key vaults, and other resources. Azure offers two primary SDKs for authentication in Go:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
Authentication is a critical process in Ratify, ensuring secure access to artifatcs in container registries, and to keys, secrets and certificates from cloud key vaults, and other resources. Azure offers two primary SDKs for authentication in Go:
Authentication is a critical process in Ratify, ensuring secure access to artifacts in container registries, and to keys, secrets and certificates from cloud key vaults, and other resources. Azure offers two primary SDKs for authentication in Go:

There is another option that can be used which is the default azure credential: `azidentity.NewDefaultAzureCredential`. It's an opinionated, preconfigured chain of credentials and is designed to support many environments, along with the most common authentication flows and developer tools. In graphical form, the underlying chain looks like this:
![image](../img/AzureAuthRefactor/image.png)

Howecer, this option is not recommended for the following reasons:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
Howecer, this option is not recommended for the following reasons:
However, this option is not recommended for the following reasons:

"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
)

func NewChainedCredential() (*azidentity.ChainedTokenCredential, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: I assume this proposed implementation is going to change now to take into account different client ids not specified via env variables?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants