-
Notifications
You must be signed in to change notification settings - Fork 23
CLOUDP-328217: Automation agent password secret #566
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
Open
filipcirtog
wants to merge
5
commits into
master
Choose a base branch
from
CLOUDP-328217/automation-agent-password-secret
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,17 @@ | ||
| package authentication | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| "go.uber.org/zap" | ||
| "golang.org/x/xerrors" | ||
| "k8s.io/apimachinery/pkg/types" | ||
|
|
||
| mdbv1 "github.com/mongodb/mongodb-kubernetes/api/v1/mdb" | ||
| "github.com/mongodb/mongodb-kubernetes/controllers/om" | ||
| "github.com/mongodb/mongodb-kubernetes/controllers/operator/ldap" | ||
| "github.com/mongodb/mongodb-kubernetes/controllers/operator/oidc" | ||
| kubernetesClient "github.com/mongodb/mongodb-kubernetes/mongodb-community-operator/pkg/kube/client" | ||
| "github.com/mongodb/mongodb-kubernetes/pkg/util" | ||
| ) | ||
|
|
||
|
|
@@ -82,7 +86,7 @@ type UserOptions struct { | |
|
|
||
| // Configure will configure all the specified authentication Mechanisms. We need to ensure we wait for | ||
| // the agents to reach ready state after each operation as prematurely updating the automation config can cause the agents to get stuck. | ||
| func Configure(conn om.Connection, opts Options, isRecovering bool, log *zap.SugaredLogger) error { | ||
| func Configure(client kubernetesClient.Client, ctx context.Context, mdbNamespacedName *types.NamespacedName, conn om.Connection, opts Options, isRecovering bool, log *zap.SugaredLogger) error { | ||
| log.Infow("ensuring correct deployment mechanisms", "ProcessNames", opts.ProcessNames, "Mechanisms", opts.Mechanisms) | ||
|
|
||
| // In case we're recovering, we can push all changes at once, because the mechanism is triggered after 20min by default. | ||
|
|
@@ -113,7 +117,7 @@ func Configure(conn om.Connection, opts Options, isRecovering bool, log *zap.Sug | |
|
|
||
| // once we have made sure that the deployment authentication mechanism array contains the desired auth mechanism | ||
| // we can then configure the agent authentication. | ||
| if err := enableAgentAuthentication(conn, opts, log); err != nil { | ||
| if err := enableAgentAuthentication(client, ctx, mdbNamespacedName, conn, opts, log); err != nil { | ||
| return xerrors.Errorf("error enabling agent authentication: %w", err) | ||
| } | ||
| if err := waitForReadyStateIfNeeded(); err != nil { | ||
|
|
@@ -151,7 +155,7 @@ func Configure(conn om.Connection, opts Options, isRecovering bool, log *zap.Sug | |
|
|
||
| // Disable disables all authentication mechanisms, and waits for the agents to reach goal state. It is still required to provide | ||
| // automation agent username, password and keyfile contents to ensure a valid Automation Config. | ||
| func Disable(conn om.Connection, opts Options, deleteUsers bool, log *zap.SugaredLogger) error { | ||
| func Disable(client kubernetesClient.Client, ctx context.Context, mdbNamespacedName *types.NamespacedName, conn om.Connection, opts Options, deleteUsers bool, log *zap.SugaredLogger) error { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| ac, err := conn.ReadAutomationConfig() | ||
| if err != nil { | ||
| return xerrors.Errorf("error reading automation config: %w", err) | ||
|
|
@@ -181,7 +185,7 @@ func Disable(conn om.Connection, opts Options, deleteUsers bool, log *zap.Sugare | |
| if err := ac.EnsureKeyFileContents(); err != nil { | ||
| return xerrors.Errorf("error ensuring keyfile contents: %w", err) | ||
| } | ||
| if _, err := ac.EnsurePassword(); err != nil { | ||
| if _, err := ac.EnsurePassword(client, ctx, mdbNamespacedName); err != nil { | ||
| return xerrors.Errorf("error ensuring agent password: %w", err) | ||
| } | ||
|
|
||
|
|
@@ -258,7 +262,7 @@ func removeUnsupportedAgentMechanisms(conn om.Connection, opts Options, log *zap | |
|
|
||
| // enableAgentAuthentication determines which agent authentication mechanism should be configured | ||
| // and enables it in Ops Manager | ||
| func enableAgentAuthentication(conn om.Connection, opts Options, log *zap.SugaredLogger) error { | ||
| func enableAgentAuthentication(client kubernetesClient.Client, ctx context.Context, mdbNamespacedName *types.NamespacedName, conn om.Connection, opts Options, log *zap.SugaredLogger) error { | ||
| ac, err := conn.ReadAutomationConfig() | ||
| if err != nil { | ||
| return xerrors.Errorf("error reading automation config: %w", err) | ||
|
|
@@ -267,7 +271,7 @@ func enableAgentAuthentication(conn om.Connection, opts Options, log *zap.Sugare | |
| // we then configure the agent authentication for that type | ||
| mechanism := convertToMechanismOrPanic(opts.AgentMechanism, ac) | ||
|
|
||
| if err := ensureAgentAuthenticationIsConfigured(conn, opts, ac, mechanism, log); err != nil { | ||
| if err := ensureAgentAuthenticationIsConfigured(client, ctx, mdbNamespacedName, conn, opts, ac, mechanism, log); err != nil { | ||
| return xerrors.Errorf("error ensuring agent authentication is configured: %w", err) | ||
| } | ||
|
|
||
|
|
@@ -365,14 +369,14 @@ func addOrRemoveAgentClientCertificate(conn om.Connection, opts Options, log *za | |
| } | ||
|
|
||
| // ensureAgentAuthenticationIsConfigured will configure the agent authentication settings based on the desiredAgentAuthMechanism | ||
| func ensureAgentAuthenticationIsConfigured(conn om.Connection, opts Options, ac *om.AutomationConfig, mechanism Mechanism, log *zap.SugaredLogger) error { | ||
| func ensureAgentAuthenticationIsConfigured(client kubernetesClient.Client, ctx context.Context, mdbNamespacedName *types.NamespacedName, conn om.Connection, opts Options, ac *om.AutomationConfig, mechanism Mechanism, log *zap.SugaredLogger) error { | ||
| if mechanism.IsAgentAuthenticationConfigured(ac, opts) { | ||
| log.Infof("Agent authentication mechanism %s is already configured", mechanism.GetName()) | ||
| return nil | ||
| } | ||
|
|
||
| log.Infof("Enabling %s agent authentication", mechanism.GetName()) | ||
| return mechanism.EnableAgentAuthentication(conn, opts, log) | ||
| return mechanism.EnableAgentAuthentication(client, ctx, mdbNamespacedName, conn, opts, log) | ||
| } | ||
|
|
||
| // ensureDeploymentMechanisms configures the given AutomationConfig to allow deployments to | ||
|
|
||
5 changes: 4 additions & 1 deletion
5
controllers/operator/authentication/authentication_mechanism.go
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: ctx should always be first arg