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

Support OIDC for sovereign clouds #321

Merged
merged 5 commits into from
May 24, 2023

Conversation

MoChilia
Copy link
Member

@MoChilia MoChilia commented May 24, 2023

Description

This pr is going to support OIDC based authentication for sovereign clouds.

The error in #298 was related to the wrong error handling in

core.error(`${error.message.split(':')[1]}. Please make sure to give write permissions to id-token in the workflow.`);

This line was expected to capture the error in the format like Error message: xxx. However, when we used sovereign clouds then the error was thrown in

throw new Error(`Your current environment - "${environment}" is not supported for OIDC login.`);

This error was not in the format like Error message: xxx. Hence, when this error was caught, it would output the error message as mentioned in #298

Error: undefined. Please make sure to give write permissions to id-token in the workflow.

In addition, the previous code didn't throw the error and exit the process, instead, it just output the error message and continued the process. That's why we didn't expect customers to login successfully with OIDC for sovereign clouds in the previous version, but it still worked.

In this pr, we adjust the method of error handling. When the federated token is not fetched correctly, we would throw the error and exit the process. And we no longer limit customers to use OIDC for sovereign clouds. As long as the federated token is obtained successfully, we will attempt to login.

Test workflows

@MoChilia MoChilia requested a review from YanaXu May 24, 2023 06:41
@MoChilia MoChilia self-assigned this May 24, 2023
@jiasli
Copy link
Member

jiasli commented May 25, 2023

Please follow the GitHub convention for Linking a pull request to an issue.

@jiasli
Copy link
Member

jiasli commented May 25, 2023

#298 claims:

When using OIDC in azure government an error is thrown on login but still works successfully

Please provide explanations in the PR description for

  • Why the error is thrown
  • Why the login action works successfully

core.error(`Please make sure to give write permissions to id-token in the workflow.`);
throw error;
}
if (!!federatedToken) {
Copy link
Member

Choose a reason for hiding this comment

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

Under what circumstances can federatedToken be null? Won't a null federatedToken trigger an error which can be caught by L118?

let audience = core.getInput('audience', { required: false });
//generating ID-token
let audience = core.getInput('audience', { required: false });
try{
Copy link
Member

@jiasli jiasli May 25, 2023

Choose a reason for hiding this comment

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

Code style is important.

Suggested change
try{
try {

Read more from https://www.bing.com/search?q=why+is+code+style+important

let [issuer, subjectClaim] = await jwtParser(federatedToken);
console.log("Federated token details: \n issuer - " + issuer + " \n subject claim - " + subjectClaim);
}
else{
Copy link
Member

Choose a reason for hiding this comment

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

Same here

Suggested change
else{
else {

}
catch (error) {
core.error(`${error.message.split(':')[1]}. Please make sure to give write permissions to id-token in the workflow.`);
Copy link
Member

Choose a reason for hiding this comment

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

All string operations should be accompanied by an example. Otherwise, it will be difficult for future readers to understand.

}
if (!!federatedToken) {
let [issuer, subjectClaim] = await jwtParser(federatedToken);
console.log("Federated token details: \n issuer - " + issuer + " \n subject claim - " + subjectClaim);
Copy link
Member

@jiasli jiasli May 25, 2023

Choose a reason for hiding this comment

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

Trailing spaces before an \n should be removed:

Suggested change
console.log("Federated token details: \n issuer - " + issuer + " \n subject claim - " + subjectClaim);
console.log("Federated token details:\n issuer - " + issuer + "\n subject claim - " + subjectClaim);

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.

Azure US Government OIDC Feature: OpenID Connect support for AzureUSGovernment and AzureChinaCloud
3 participants