@@ -4,9 +4,10 @@ const assert = require('assert');
4
4
const fs = require ( 'fs' ) ;
5
5
const path = require ( 'path' ) ;
6
6
7
- // The max time that a GitHub action is allowed to run is 6 hours.
8
- // That seems like a reasonable default to use if no role duration is defined.
7
+ // Use 1hr as role duration when using session token or OIDC
8
+ // Otherwise, use the max duration of GitHub action (6hr)
9
9
const MAX_ACTION_RUNTIME = 6 * 3600 ;
10
+ const SESSION_ROLE_DURATION = 3600 ;
10
11
const DEFAULT_ROLE_DURATION_FOR_OIDC_ROLES = 3600 ;
11
12
const USER_AGENT = 'configure-aws-credentials-for-github-actions' ;
12
13
const MAX_TAG_VALUE_LENGTH = 256 ;
@@ -85,7 +86,7 @@ async function assumeRole(params) {
85
86
}
86
87
87
88
let assumeFunction = sts . assumeRole . bind ( sts ) ;
88
-
89
+
89
90
// These are customizations needed for the GH OIDC Provider
90
91
if ( isDefined ( webIdentityToken ) ) {
91
92
delete assumeRoleRequest . Tags ;
@@ -110,8 +111,8 @@ async function assumeRole(params) {
110
111
} catch ( error ) {
111
112
throw new Error ( `Web identity token file could not be read: ${ error . message } ` ) ;
112
113
}
113
-
114
- }
114
+
115
+ }
115
116
116
117
return assumeFunction ( assumeRoleRequest )
117
118
. promise ( )
@@ -270,7 +271,9 @@ async function run() {
270
271
const maskAccountId = core . getInput ( 'mask-aws-account-id' , { required : false } ) ;
271
272
const roleToAssume = core . getInput ( 'role-to-assume' , { required : false } ) ;
272
273
const roleExternalId = core . getInput ( 'role-external-id' , { required : false } ) ;
273
- let roleDurationSeconds = core . getInput ( 'role-duration-seconds' , { required : false } ) || MAX_ACTION_RUNTIME ;
274
+ let roleDurationSeconds = core . getInput ( 'role-duration-seconds' , { required : false } )
275
+ || ( sessionToken && SESSION_ROLE_DURATION )
276
+ || MAX_ACTION_RUNTIME ;
274
277
const roleSessionName = core . getInput ( 'role-session-name' , { required : false } ) || ROLE_SESSION_NAME ;
275
278
const roleSkipSessionTaggingInput = core . getInput ( 'role-skip-session-tagging' , { required : false } ) || 'false' ;
276
279
const roleSkipSessionTagging = roleSkipSessionTaggingInput . toLowerCase ( ) === 'true' ;
@@ -304,7 +307,7 @@ async function run() {
304
307
305
308
exportCredentials ( { accessKeyId, secretAccessKey, sessionToken} ) ;
306
309
}
307
-
310
+
308
311
// Attempt to load credentials from the GitHub OIDC provider.
309
312
// If a user provides an IAM Role Arn and DOESN'T provide an Access Key Id
310
313
// The only way to assume the role is via GitHub's OIDC provider.
0 commit comments