-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[backend/frontend] Fix localStrategy on force env (#15311) #15333
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
ee3995c
[bcakend/frontend] Fix localStrategy on force env (#15311)
aHenryJard 9901c46
With tests green it's better
aHenryJard 9b1802d
I missed an import change
aHenryJard a635892
Update test and disable local toggle in UI
aHenryJard bf5b267
A new test
aHenryJard cc3c96e
Add translations
aHenryJard 49e62ac
Fixing all tests
aHenryJard 8e3c1e6
Add use case on force local
aHenryJard e52f16d
Cleanup TODOs and taking PR feedbacks
aHenryJard 804ed88
Better test comment and naming
aHenryJard 6de54f9
Fix behavior with LDAP enabled and local disabled and add test coverage
aHenryJard 0d9d2fc
Left over on provider revert
aHenryJard File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
104 changes: 104 additions & 0 deletions
104
opencti-platform/opencti-graphql/src/domain/setting-auth.ts
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| // -- Built-in authentication strategy settings -- | ||
| // These mutations update the Settings entity AND trigger live re-registration | ||
| // of the corresponding authentication provider. | ||
|
aHenryJard marked this conversation as resolved.
|
||
|
|
||
| import { patchAttribute } from '../database/middleware'; | ||
| import { publishUserAction } from '../listener/UserActionListener'; | ||
| import { CERT_PROVIDER } from '../modules/authenticationProvider/provider-cert'; | ||
| import { HEADERS_PROVIDER } from '../modules/authenticationProvider/provider-headers'; | ||
| import { LOCAL_PROVIDER } from '../modules/authenticationProvider/provider-local'; | ||
| import { | ||
| AuthType, | ||
| CERT_STRATEGY_IDENTIFIER, | ||
| EnvStrategyType, | ||
| HEADERS_STRATEGY_IDENTIFIER, | ||
| isLocalAuthForcedEnabledFromEnv, | ||
| LOCAL_STRATEGY_IDENTIFIER, | ||
| PROVIDERS, | ||
| } from '../modules/authenticationProvider/providers-configuration'; | ||
| import { ENTITY_TYPE_SETTINGS } from '../schema/internalObject'; | ||
| import type { BasicStoreSettings } from '../types/settings'; | ||
| import type { AuthContext, AuthUser } from '../types/user'; | ||
| import { notify } from '../database/redis'; | ||
| import { BUS_TOPICS } from '../config/conf'; | ||
| import type { CertAuthConfigInput, HeadersAuthConfigInput, LocalAuthConfigInput } from '../generated/graphql'; | ||
|
|
||
| export const buildAvailableProviders = async (platformSettings: BasicStoreSettings) => { | ||
| const availableProviders = [...PROVIDERS]; | ||
| if (platformSettings.local_auth?.enabled || isLocalAuthForcedEnabledFromEnv()) { | ||
| availableProviders.push({ | ||
| name: platformSettings.local_auth?.button_label_override || 'local', | ||
| type: AuthType.AUTH_FORM, | ||
| strategy: EnvStrategyType.STRATEGY_LOCAL, | ||
| provider: LOCAL_PROVIDER?.provider ?? LOCAL_STRATEGY_IDENTIFIER, | ||
| }); | ||
|
aHenryJard marked this conversation as resolved.
|
||
| } | ||
| if (platformSettings.cert_auth?.enabled) { | ||
| availableProviders.push({ | ||
| name: platformSettings.cert_auth?.button_label_override || 'cert', | ||
| type: AuthType.AUTH_SSO, | ||
| strategy: EnvStrategyType.STRATEGY_CERT, | ||
| provider: CERT_PROVIDER?.provider ?? CERT_STRATEGY_IDENTIFIER, | ||
| }); | ||
| } | ||
| if (platformSettings.headers_auth?.enabled) { | ||
| availableProviders.push({ | ||
| name: platformSettings.headers_auth?.button_label_override || 'headers', | ||
| type: AuthType.AUTH_SSO, | ||
| strategy: EnvStrategyType.STRATEGY_HEADER, | ||
| provider: HEADERS_PROVIDER?.provider ?? HEADERS_STRATEGY_IDENTIFIER, | ||
| }); | ||
| } | ||
| return availableProviders; | ||
| }; | ||
|
|
||
| export const updateLocalAuth = async (context: AuthContext, user: AuthUser, settingsId: string, input: LocalAuthConfigInput) => { | ||
| const patch = { | ||
| local_auth: { enabled: input.enabled }, | ||
| ...(input.password_policy_min_length !== undefined && { password_policy_min_length: input.password_policy_min_length }), | ||
| ...(input.password_policy_max_length !== undefined && { password_policy_max_length: input.password_policy_max_length }), | ||
| ...(input.password_policy_min_symbols !== undefined && { password_policy_min_symbols: input.password_policy_min_symbols }), | ||
| ...(input.password_policy_min_numbers !== undefined && { password_policy_min_numbers: input.password_policy_min_numbers }), | ||
| ...(input.password_policy_min_words !== undefined && { password_policy_min_words: input.password_policy_min_words }), | ||
| ...(input.password_policy_min_lowercase !== undefined && { password_policy_min_lowercase: input.password_policy_min_lowercase }), | ||
| ...(input.password_policy_min_uppercase !== undefined && { password_policy_min_uppercase: input.password_policy_min_uppercase }), | ||
| }; | ||
| const { element } = await patchAttribute(context, user, settingsId, ENTITY_TYPE_SETTINGS, patch); | ||
| await publishUserAction({ | ||
| user, | ||
| event_type: 'mutation', | ||
| event_scope: 'update', | ||
| event_access: 'administration', | ||
| message: 'updates `local authentication settings` for `platform settings`', | ||
| context_data: { id: settingsId, entity_type: ENTITY_TYPE_SETTINGS, input: patch }, | ||
| }); | ||
| return notify(BUS_TOPICS[ENTITY_TYPE_SETTINGS].EDIT_TOPIC, element, user); | ||
| }; | ||
|
|
||
| export const updateCertAuth = async (context: AuthContext, user: AuthUser, settingsId: string, input: CertAuthConfigInput) => { | ||
| const patch = { cert_auth: input }; | ||
| const { element } = await patchAttribute(context, user, settingsId, ENTITY_TYPE_SETTINGS, patch); | ||
| await publishUserAction({ | ||
| user, | ||
| event_type: 'mutation', | ||
| event_scope: 'update', | ||
| event_access: 'administration', | ||
| message: 'updates `cert authentication settings` for `platform settings`', | ||
| context_data: { id: settingsId, entity_type: ENTITY_TYPE_SETTINGS, input: patch }, | ||
| }); | ||
| return notify(BUS_TOPICS[ENTITY_TYPE_SETTINGS].EDIT_TOPIC, element, user); | ||
| }; | ||
|
|
||
| export const updateHeaderAuth = async (context: AuthContext, user: AuthUser, settingsId: string, input: HeadersAuthConfigInput) => { | ||
| const patch = { headers_auth: input }; | ||
| const { element } = await patchAttribute(context, user, settingsId, ENTITY_TYPE_SETTINGS, patch); | ||
| await publishUserAction({ | ||
| user, | ||
| event_type: 'mutation', | ||
| event_scope: 'update', | ||
| event_access: 'administration', | ||
| message: 'updates `header authentication settings` for `platform settings`', | ||
| context_data: { id: settingsId, entity_type: ENTITY_TYPE_SETTINGS, input: patch }, | ||
| }); | ||
| return notify(BUS_TOPICS[ENTITY_TYPE_SETTINGS].EDIT_TOPIC, element, user); | ||
| }; | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.