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

rules: add simple domain allow list #192

Merged
merged 1 commit into from
Mar 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions internal/cli/data/rule-template-simple-domain-allow-list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* @title Email domain allow list
* @overview Only allow access to users with specific allow list email domains.
* @gallery true
* @category access control
*
* This rule will only allow access to users with specific email domains.
*
*/

function emailDomainAllowList(user, context, callback) {
// Access should only be granted to verified users.
if (!user.email || !user.email_verified) {
return callback(new UnauthorizedError('Access denied.'));
}

const allowList = ['example.com', 'example.org']; //authorized domains
const userHasAccess = allowList.some(function (domain) {
const emailSplit = user.email.split('@');
return emailSplit[emailSplit.length - 1].toLowerCase() === domain;
});

if (!userHasAccess) {
return callback(new UnauthorizedError('Access denied.'));
}

return callback(null, user, context);
}
1 change: 1 addition & 0 deletions internal/cli/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ var (
{"Empty rule", ruleTemplateEmptyRule},
{"Add email to access token", ruleTemplateAddEmailToAccessToken},
{"Check last password reset", ruleTemplateCheckLastPasswordReset},
{"Simple domain allow list", ruleTemplateSimpleDomainAllowList},
{"IP address allow list", ruleTemplateIPAddressAllowList},
{"IP address deny list", ruleTemplateIPAddressDenyList},
}
Expand Down
3 changes: 3 additions & 0 deletions internal/cli/rules_embed.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@ var (

//go:embed data/rule-template-ip-address-deny-list.js
ruleTemplateIPAddressDenyList string

//go:embed data/rule-template-simple-domain-allow-list.js
ruleTemplateSimpleDomainAllowList string
)