-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch from Azure AD to Entra ID (#845)
* Switch from azure AD to Entra ID * Update documentation * update tests to support entra id * fix docs comments * migration first cut * Fix errors in migration
- Loading branch information
1 parent
c910a05
commit 676e08e
Showing
14 changed files
with
108 additions
and
50 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# frozen_string_literal: true | ||
|
||
# Migration to move Azure AD users to Entra ID | ||
class AzureAdToEntraId < ActiveRecord::Migration[7.2] | ||
def up | ||
azure_user_list = User.where(provider: 'azure_activedirectory_v2').all | ||
|
||
# If there are no AD users in the database, exit early. | ||
unless azure_user_list.count.positive? | ||
Rails.logger.info 'No Azure AD users in database. No Migration needed.' | ||
return | ||
end | ||
|
||
tenant_id = find_tenant_id | ||
|
||
azure_user_list.each { |u| migrate_user(u, tenant_id) } | ||
end | ||
|
||
# Tries to get tenant_id from the entra_id credentials. Raises an error to abort the migration if it cannot be found. | ||
def find_tenant_id | ||
begin | ||
tenant_id = Rails.application.credentials.entra_id[:tenant_id] | ||
rescue NoMethodError | ||
error_msg = 'Could not find credentials for Entra ID' | ||
Rails.logger.error error_msg | ||
raise StandardError, error_msg | ||
end | ||
|
||
unless tenant_id | ||
error_msg = 'tenant_id for entra_id is not specified' | ||
Rails.logger.error error_msg | ||
raise StandardError, error_msg | ||
end | ||
|
||
tenant_id | ||
end | ||
|
||
def migrate_user(user, tenant_id) | ||
old_uid = user.uid | ||
new_uid = tenant_id + old_uid | ||
user.uid = new_uid | ||
user.provider = 'entra_id' | ||
user.save! | ||
end | ||
|
||
def down | ||
raise ActiveRecord::IrreversibleMigration | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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 |
---|---|---|
|
@@ -27,7 +27,7 @@ def invalid_developer_login_setup | |
|
||
module OmniauthAzureHelper | ||
RESPONSE = { | ||
provider: 'azure_activedirectory_v2', | ||
provider: 'entra_id', | ||
uid: '12345678-90-abcd-ef12-34567890abcd', | ||
info: { | ||
email: '[email protected]', | ||
|
@@ -49,14 +49,14 @@ module OmniauthAzureHelper | |
|
||
def valid_azure_login_setup | ||
OmniAuth.config.test_mode = true | ||
OmniAuth.config.mock_auth[:azure_activedirectory_v2] = OmniAuth::AuthHash.new(RESPONSE) | ||
Rails.application.env_config['omniauth.auth'] = OmniAuth.config.mock_auth[:azure_activedirectory_v2] | ||
OmniAuth.config.mock_auth[:entra_id] = OmniAuth::AuthHash.new(RESPONSE) | ||
Rails.application.env_config['omniauth.auth'] = OmniAuth.config.mock_auth[:entra_id] | ||
end | ||
|
||
def invalid_azure_login_setup | ||
OmniAuth.config.test_mode = true | ||
OmniAuth.config.mock_auth[:azure_activedirectory_v2] = :invalid_credentials | ||
Rails.application.env_config['omniauth.auth'] = OmniAuth.config.mock_auth[:azure_activedirectory_v2] | ||
OmniAuth.config.mock_auth[:entra_id] = :invalid_credentials | ||
Rails.application.env_config['omniauth.auth'] = OmniAuth.config.mock_auth[:entra_id] | ||
end | ||
end | ||
|
||
|