Skip to content

Added OIDC support for login action - #147

Merged
Balaga Gayatri (BALAGA-GAYATRI) merged 48 commits into
Azure:oidc-supportfrom
BALAGA-GAYATRI:oidc-support
Oct 11, 2021
Merged

Balaga Gayatri (BALAGA-GAYATRI) merged 48 commits into
Azure:oidc-supportfrom
BALAGA-GAYATRI:oidc-support

Conversation

@BALAGA-GAYATRI

Copy link
Copy Markdown
Contributor

No description provided.

Comment thread src/main.ts Outdated
Comment on lines +47 to +75
//Check for the credentials in individual parameters in the workflow.
var servicePrincipalId = core.getInput('client-id', { required: false });;
var servicePrincipalKey = null;
var tenantId = core.getInput('tenant-id', { required: false });
var subscriptionId = core.getInput('subscription-id', { required: false });
var resourceManagerEndpointUrl = "https://management.azure.com/";
var enableOIDC= true;
// If any of the individual credentials (clent_id, tenat_id, subscription_id) are missing
if(!servicePrincipalId || !tenantId || !(subscriptionId || allowNoSubscriptionsLogin)){
//If all of the individual credentials (clent_id, tenat_id, subscription_id) are missing in workflow inputs, checking for creds object.
if(!servicePrincipalId && !tenantId && (!subscriptionId || !allowNoSubscriptionsLogin)){
console.log('checking line 55 condition..')
if(creds) {
console.log('using creds JSON...')
enableOIDC = false;
servicePrincipalId = secrets.getSecret("$.clientId", true);
servicePrincipalKey= secrets.getSecret("$.clientSecret", true);
tenantId = secrets.getSecret("$.tenantId", true);
subscriptionId = secrets.getSecret("$.subscriptionId", true);
resourceManagerEndpointUrl = secrets.getSecret("$.resourceManagerEndpointUrl", false);
}
else{
throw new Error("Credentials are not passed for Login action.");
}
}
//If any few of the individual credentials are missing
else
throw new Error("Few credentials are missing.ClientId,tenantId are mandatory. SubscriptionId is also mandatory if allow-no-subscriptions is not set.");
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Put it into a factory pattern. Your code will be much cleaner with no if/else conditions you have used below for enableOIDC check.

Comment thread src/main.ts Outdated
Comment thread lib/main.js Outdated
Comment thread lib/main.js
Comment thread lib/main.js
if (!servicePrincipalId || !servicePrincipalKey || !tenantId) {
throw new Error("Not all values are present in the creds object. Ensure clientId, clientSecret and tenantId are supplied.");
//Check for the credentials in individual parameters in the workflow.
var servicePrincipalId = core.getInput('client-id', { required: false });

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should we name this var as clientId only to be same as Input name

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is as per previous design only. clientID is treated as serviceprincipalId and clientSecret as serviceprincipalKey.

Comment thread lib/main.js
var servicePrincipalKey = null;
var tenantId = core.getInput('tenant-id', { required: false });
var subscriptionId = core.getInput('subscription-id', { required: false });
var resourceManagerEndpointUrl = "https://management.azure.com/";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is this fixed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes. For other clouds it is different. For public cloud it is constant.

Comment thread lib/main.js Outdated
var subscriptionId = core.getInput('subscription-id', { required: false });
var resourceManagerEndpointUrl = "https://management.azure.com/";
var enableOIDC = true;
// If any of the individual credentials (clent_id, tenat_id, subscription_id) are missing

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: please add newlines for formatting, readability.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

added

Comment thread lib/main.js
var servicePrincipalId = core.getInput('client-id', { required: false });
;
var servicePrincipalKey = null;
var tenantId = core.getInput('tenant-id', { required: false });

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should these also be individual secrets like in creds object?

Comment thread src/main.ts Outdated
execOptions.silent = !!silent;
try {
await exec.exec(`"${azPath}" ${command}`, args, execOptions);
core.debug(args);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You shouldn't put log here, it may expose credentials if it doesn't get masked by GitHub runner.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

removed 👍🏻

Comment thread src/main.ts Outdated
var args = [];
if (enableOIDC) {
args = [
"--allow-no-subscriptions",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You can create a base args array that contains common keys and based on the specific parameter values you can append to it.
Like if allowNoSubscriptionsLogin is true -> append "--allow-no-subscriptions" to args, same for other keys.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done!✅

Comment thread src/main.ts
if (enableAzPSSession)
throw new Error(`Powershell login is not supported with OIDC.`);
} else {
throw new Error("Could not get ID token for authentication.");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Does OIDC send some error message in case of failure. if it is we should also show that to users, so user can debug the error. Here user can be clueless, what has gone wrong and he can't debug.

Comment thread src/main.ts Outdated
if (!servicePrincipalId || !tenantId || !(subscriptionId || allowNoSubscriptionsLogin)) {
//If all of the individual credentials (clent_id, tenat_id, subscription_id) are missing in workflow inputs, checking for creds object.
if (!servicePrincipalId && !tenantId && (!subscriptionId || !allowNoSubscriptionsLogin)) {
if (creds) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

What if the user has passed some parameters as inputs and some under creds object? As per your code, it will go for creds object which is ok. But Should we let users pass parameters to both?

Comment thread lib/main.js
"-u", servicePrincipalId,
"--tenant", tenantId
];
if (allowNoSubscriptionsLogin) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
if (allowNoSubscriptionsLogin) {
if (allowNoSubscriptionsLogin) {
commonArgs = commonArgs.concat("--allow-no-subscriptions");
}
if (enableOIDC) {
commonArgs = commonArgs.concat("--federated-token", idToken);
}
else {
commonArgs = commonArgs.concat("-p", servicePrincipalKey);
}
yield executeAzCliCommand(`login`, true, {}, commonArgs);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@BALAGA-GAYATRI
Balaga Gayatri (BALAGA-GAYATRI) merged commit a4b1865 into Azure:oidc-support Oct 11, 2021
Kanika Pasrija (kanika1894) added a commit that referenced this pull request Oct 22, 2021
* Added OIDC support for login action (#147)

* OIDC support for Powershell login (#156)

* OIDC support ps (#155)

ps login support

* Update main.ts

* formatting code

* nit changes

Co-authored-by: Balaga Gayatri <balaga-gayatri@github.com>
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.

3 participants