-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #480 from mozilla-iam/move_duosecurity
Migrate duoSecurity into accessRules
- Loading branch information
Showing
6 changed files
with
119 additions
and
297 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,18 +9,17 @@ exports.onExecutePostLogin = async (event, api) => { | |
console.log("Running actions:", "accessRules"); | ||
|
||
// Retrieve and return a secret from AWS Secrets Manager | ||
const getSecrets = async (AWS, accessKeyId, secretAccessKey) => { | ||
const getSecrets = async () => { | ||
try { | ||
|
||
if (!accessKeyId || !secretAccessKey) { | ||
if (!event.secrets.accessKeyId || !event.secrets.secretAccessKey) { | ||
throw new Error('AWS access keys are not defined.'); | ||
} | ||
|
||
// set AWS config so we can retrieve secrets | ||
// Set up AWS client | ||
AWS.config.update({ | ||
region: 'us-west-2', | ||
accessKeyId: accessKeyId, | ||
secretAccessKey: secretAccessKey | ||
accessKeyId: event.secrets.accessKeyId, | ||
secretAccessKey: event.secrets.secretAccessKey | ||
}); | ||
|
||
const secretsManager = new AWS.SecretsManager(); | ||
|
@@ -40,9 +39,7 @@ exports.onExecutePostLogin = async (event, api) => { | |
} | ||
|
||
// Load secrets | ||
const accessKeyId = event.secrets.accessKeyId; | ||
const secretAccessKey = event.secrets.secretAccessKey; | ||
const secrets = await getSecrets(AWS, accessKeyId, secretAccessKey); | ||
const secrets = await getSecrets(); | ||
const jwtMsgsRsaSkey = secrets.jwtMsgsRsaSkey; | ||
|
||
// postError(code) | ||
|
@@ -84,6 +81,12 @@ exports.onExecutePostLogin = async (event, api) => { | |
} | ||
} | ||
|
||
if (!event.user.email_verified) { | ||
console.log(`User primary email NOT verified, refusing login for ${event.user.email}`); | ||
// This post error is broken in sso dashboard | ||
postError("primarynotverified", event, api, jwt, jwtMsgsRsaSkey); | ||
return; | ||
} | ||
|
||
const namespace = 'https://sso.mozilla.com/claim'; | ||
|
||
|
@@ -93,6 +96,13 @@ exports.onExecutePostLogin = async (event, api) => { | |
'[email protected]', // MOC see: https://bugzilla.mozilla.org/show_bug.cgi?id=1423903 | ||
]; | ||
|
||
const duoConfig = { | ||
"host": event.secrets.duo_apihost_mozilla, | ||
"ikey": event.secrets.duo_ikey_mozilla, | ||
"skey": event.secrets.duo_skey_mozilla, | ||
"username": event.user.email, | ||
}; | ||
|
||
// Check if array A has any occurrence from array B | ||
const hasCommonElements = (A, B) => { | ||
return A.some(element => B.includes(element)); | ||
|
@@ -235,6 +245,17 @@ exports.onExecutePostLogin = async (event, api) => { | |
let aai = []; | ||
let aal = "UNKNOWN"; | ||
|
||
// Allow certain LDAP service accounts to fake their MFA. For all other LDAPi accounts, enforce MFA | ||
if (event.connection.strategy === "ad") { | ||
if (mfaBypassAccounts.includes(event.user.email)) { | ||
console.log(`LDAP service account (${event.user.email}) is allowed to bypass MFA`); | ||
aai.push("2FA"); | ||
} else { | ||
api.multifactor.enable("duo", { "providerOptions": duoConfig, "allowRememberBrowser": true }); | ||
console.log(`duosecurity: ${event.user.email} is in LDAP and requires 2FA check`); | ||
} | ||
} | ||
|
||
const profileData = getProfileData(event.connection.name); | ||
|
||
//GitHub attribute | ||
|
@@ -266,12 +287,6 @@ exports.onExecutePostLogin = async (event, api) => { | |
aai.push("HIGH_ASSURANCE_IDP"); | ||
} | ||
|
||
// Allow certain LDAP service accounts to fake their MFA | ||
if (mfaBypassAccounts.includes(event.user.email) && (event.connection.strategy === "ad")) { | ||
console.log(`LDAP service account (${event.user.email}) is allowed to bypass MFA`); | ||
aai.push("2FA"); | ||
} | ||
|
||
// AAI (AUTHENTICATOR ASSURANCE INDICATOR) REQUIREMENTS | ||
// | ||
// Note that user.aai is set in another rule (rules/aai.js) | ||
|
@@ -369,7 +384,6 @@ exports.onExecutePostLogin = async (event, api) => { | |
postError(decision); | ||
return; | ||
} | ||
|
||
} catch (err) { | ||
// All error should be caught here and we return the callback handler with the error | ||
console.log("AccessRules:", err); | ||
|
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.