controller

package
v0.62.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 24, 2026 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CRSecretPollInterval = 5 * time.Second

CRSecretPollInterval is the delay between CR health checks after deleting a secret.

View Source
var CRSecretPollTimeout = 60 * time.Second

CRSecretPollTimeout is the maximum time to wait for CCO to recreate a secret.

View Source
var RotationRequiredActions = []string{
	"iam:CreateAccessKey",
	"iam:CreateUser",
	"iam:DeleteAccessKey",
	"iam:DeleteUser",
	"iam:DeleteUserPolicy",
	"iam:GetUser",
	"iam:GetUserPolicy",
	"iam:ListAccessKeys",
	"iam:PutUserPolicy",
	"iam:TagUser",
}

RotationRequiredActions are the IAM actions needed by the rotation tooling to create/delete access keys and manage IAM users.

View Source
var SyncMaxRetries = 6

SyncMaxRetries is the maximum number of ClusterSync poll attempts.

View Source
var SyncPollInterval = 5 * time.Second

SyncPollInterval is the delay between ClusterSync status checks.

Functions

func DeleteCredentialSecrets added in v0.62.0

func DeleteCredentialSecrets(ctx context.Context, managedClient client.Client, in io.Reader, out io.Writer) error

DeleteCredentialSecrets sequentially deletes each credential secret and waits for CCO to recreate it before proceeding to the next one.

func RenderCredRequestTable added in v0.62.0

func RenderCredRequestTable(report *DiagnosticReport, out io.Writer)

RenderCredRequestTable outputs the CredentialRequest secrets table.

func RenderReport added in v0.62.0

func RenderReport(report *DiagnosticReport, out io.Writer)

RenderReport formats the diagnostic report as a human-readable table.

func RotateSecret

func RotateSecret(ctx context.Context, input *RotateSecretInput) error

RotateSecret performs the IAM credential rotation workflow:

  1. Validates the Account CR (not STS, has iamUserId label)
  2. Resolves the osdManagedAdmin username
  3. Verifies rotation permissions via SimulatePrincipalPolicy
  4. Creates a new IAM access key
  5. Updates k8s secrets on hive
  6. Creates a SyncSet to push credentials to the cluster
  7. Polls ClusterSync for completion and cleans up the SyncSet
  8. Optionally rotates osdCcsAdmin credentials

func VerifyRotationPermissions

func VerifyRotationPermissions(out io.Writer, awsClient awsprovider.Client, accountID string, username string) error

VerifyRotationPermissions checks if the assumed role has the necessary IAM permissions to perform secret rotation by simulating the required actions. Uses simulateActions internally for consistency with the diagnostic path.

Types

type AWSCredsInput added in v0.62.0

type AWSCredsInput struct {
	ClusterID         string
	ClusterName       string
	ClusterExternalID string
	IsCCS             bool
	AWSAccountID      string
	AccountCRName     string
	Account           *awsv1alpha1.Account
	AdminUsername     string
	AwsClient         awsprovider.Client
	HiveKubeClient    client.Client
	ManagedClient     client.Client
	Log               *logrus.Logger
	Out               io.Writer
}

AWSCredsInput holds all resolved dependencies needed for both diagnostics and rotation. The CLI layer resolves AWS and k8s clients before calling DiagnoseCredentials or RotateCredentials.

type CredRequestStatus added in v0.62.0

type CredRequestStatus struct {
	CredRequestName string
	SecretName      string
	Namespace       string
	Age             time.Duration
	Exists          bool
	NeedsRecreation bool
	ErrorMessage    string
}

type DiagnosticReport added in v0.62.0

type DiagnosticReport struct {
	ClusterID         string
	ClusterName       string
	ClusterExternalID string
	IsCCS             bool
	AWSAccountID      string
	AccountCRName     string

	ManagedAdminUser string
	CcsAdminUser     string
	CallerARN        string
	CallerAccount    string

	Keys         []KeyStatus
	Secrets      []SecretStatus
	CredRequests []CredRequestStatus
	Permissions  []PermissionResult
	Findings     []Finding

	AllPermissionsOK bool
	AllSecretsInSync bool
	RootKeyInSync    bool
	ClusterRootKeyID string
	HiveAccountKeyID string
}

func DiagnoseCRSecrets added in v0.62.0

func DiagnoseCRSecrets(ctx context.Context, hiveClient client.Client, managedClient client.Client, accountCRName string, account *awsv1alpha1.Account, out io.Writer) (*DiagnosticReport, error)

DiagnoseCRSecrets produces a lightweight report of just the CredentialRequest secrets, comparing the cluster's root credential (kube-system/aws-creds) against the Hive account secret to detect staleness.

func DiagnoseCredentials added in v0.62.0

func DiagnoseCredentials(ctx context.Context, input *AWSCredsInput) (*DiagnosticReport, error)

DiagnoseCredentials runs a full read-only diagnostic of IAM keys, Hive secrets, CredentialRequests, and IAM permissions, returning a structured report.

type Finding added in v0.62.0

type Finding struct {
	Severity string // "OK", "WARN", "FAIL"
	Message  string
	Guidance string
}

type InsufficientPermissionsError

type InsufficientPermissionsError struct {
	DeniedActions []string
}

InsufficientPermissionsError is returned when SimulatePrincipalPolicy reports that one or more required IAM actions are denied.

func (*InsufficientPermissionsError) Error

Error returns a human-readable message listing the denied IAM actions.

type KeyStatus added in v0.62.0

type KeyStatus struct {
	UserName    string
	AccessKeyID string
	Age         time.Duration
	CreateDate  time.Time
	LastUsed    string
	Status      string
	HiveMatch   bool
}

type PermissionResult added in v0.62.0

type PermissionResult struct {
	Action      string
	Allowed     bool
	Category    string   // "rotation" or "credreq"
	RequestedBy []string // CR names that request this action (credreq category only)
}

type RotateSecretInput

type RotateSecretInput struct {
	// AccountCRName is the name of the Account CR.
	AccountCRName string

	// Account is the pre-fetched Account CR.
	Account *awsv1alpha1.Account

	// OsdManagedAdminUsername is an explicit admin username override.
	// If empty, it is derived from the Account CR's iamUserId label.
	OsdManagedAdminUsername string

	// UpdateManagedAdminCreds controls whether osdManagedAdmin credentials are rotated.
	UpdateManagedAdminCreds bool

	// UpdateCcsCreds controls whether osdCcsAdmin credentials are also rotated.
	UpdateCcsCreds bool

	// AwsClient is the fully-authenticated AWS client with permissions in the
	// target AWS account (after all role chaining has been completed).
	AwsClient awsprovider.Client

	// HiveKubeClient is the k8s client connected to the hive cluster.
	HiveKubeClient client.Client

	// ManagedClusterClient is the k8s client connected to the managed cluster
	// (via backplane using the target OCM environment). Used to delete
	// CredentialRequests so CCO recreates them with the new credentials.
	ManagedClusterClient client.Client

	// DryRun, when true, prints what actions would be taken without performing
	// any mutating operations (no AWS key creation/deletion, no k8s resource
	// creation/deletion/updates).
	DryRun bool

	// Report is the pre-computed diagnostic report from the snapshot phase.
	// Used to display key/secret context during interactive key deletion.
	Report *DiagnosticReport

	// Log is the logger for operational messages (writes to stderr).
	Log *logrus.Logger

	// SkipPermissionCheck skips the managed-admin permission verification when
	// the caller has already run diagnostics and the user confirmed despite failures.
	SkipPermissionCheck bool

	// In is the reader for interactive prompts (defaults to os.Stdin).
	In io.Reader

	// Out is the writer for structured report output (writes to stdout).
	Out io.Writer
}

RotateSecretInput holds all resolved dependencies for secret rotation. The CLI layer is responsible for resolving AWS and k8s clients before calling RotateSecret.

type SecretStatus added in v0.62.0

type SecretStatus struct {
	SecretName   string
	Namespace    string
	AccessKeyID  string
	MatchesAWS   bool
	Exists       bool
	ErrorMessage string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL