-
Notifications
You must be signed in to change notification settings - Fork 1.5k
AGENT-1448: Add IRI registry authentication support #10389
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
rwsu
wants to merge
1
commit into
openshift:main
Choose a base branch
from
rwsu:AGENT-1448
base: main
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.
+440
−10
Open
Changes from all commits
Commits
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
12 changes: 12 additions & 0 deletions
12
data/data/manifests/bootkube/internal-release-image-registry-auth-secret.yaml.template
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,12 @@ | ||
| apiVersion: v1 | ||
| kind: Secret | ||
| metadata: | ||
| name: internal-release-image-registry-auth | ||
| namespace: openshift-machine-config-operator | ||
| annotations: | ||
| openshift.io/description: Secret containing the InternalReleaseImage registry authentication credentials | ||
| openshift.io/owning-component: Machine Config Operator | ||
| type: Opaque | ||
| data: | ||
| htpasswd: {{.IriRegistryHtpasswd}} | ||
| password: {{.IriRegistryPassword}} |
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
85 changes: 85 additions & 0 deletions
85
pkg/asset/templates/content/bootkube/internal-release-image-registry-auth-secret.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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| package bootkube | ||
|
|
||
| import ( | ||
| "context" | ||
| "os" | ||
| "path/filepath" | ||
|
|
||
| "github.com/openshift/api/features" | ||
| "github.com/openshift/installer/pkg/asset" | ||
| "github.com/openshift/installer/pkg/asset/installconfig" | ||
| "github.com/openshift/installer/pkg/asset/templates/content" | ||
| "github.com/openshift/installer/pkg/asset/templates/content/manifests" | ||
| ) | ||
|
|
||
| const ( | ||
| internalReleaseImageRegistryAuthSecretFileName = "internal-release-image-registry-auth-secret.yaml.template" | ||
| ) | ||
|
|
||
| var _ asset.WritableAsset = (*InternalReleaseImageRegistryAuthSecret)(nil) | ||
|
|
||
| // InternalReleaseImageRegistryAuthSecret is the constant to represent contents of internal-release-image-registry-auth-secret.yaml.template file. | ||
| type InternalReleaseImageRegistryAuthSecret struct { | ||
| FileList []*asset.File | ||
| } | ||
|
|
||
| // Dependencies returns all of the dependencies directly needed by the asset. | ||
| func (t *InternalReleaseImageRegistryAuthSecret) Dependencies() []asset.Asset { | ||
| return []asset.Asset{ | ||
| &installconfig.InstallConfig{}, | ||
| &manifests.InternalReleaseImage{}, | ||
| } | ||
| } | ||
|
|
||
| // Name returns the human-friendly name of the asset. | ||
| func (t *InternalReleaseImageRegistryAuthSecret) Name() string { | ||
| return "InternalReleaseImageRegistryAuthSecret" | ||
| } | ||
|
|
||
| // Generate generates the actual files by this asset. | ||
| func (t *InternalReleaseImageRegistryAuthSecret) Generate(_ context.Context, dependencies asset.Parents) error { | ||
| installConfig := &installconfig.InstallConfig{} | ||
| iri := &manifests.InternalReleaseImage{} | ||
|
|
||
| dependencies.Get(installConfig, iri) | ||
|
|
||
| if !installConfig.Config.EnabledFeatureGates().Enabled(features.FeatureGateNoRegistryClusterInstall) { | ||
| return nil | ||
| } | ||
|
|
||
| // Skip if InternalReleaseImage manifest wasn't found. | ||
| if len(iri.FileList) == 0 { | ||
| return nil | ||
| } | ||
|
|
||
| fileName := internalReleaseImageRegistryAuthSecretFileName | ||
| data, err := content.GetBootkubeTemplate(fileName) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| t.FileList = []*asset.File{ | ||
| { | ||
| Filename: filepath.Join(content.TemplateDir, fileName), | ||
| Data: data, | ||
| }, | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // Files returns the files generated by the asset. | ||
| func (t *InternalReleaseImageRegistryAuthSecret) Files() []*asset.File { | ||
| return t.FileList | ||
| } | ||
|
|
||
| // Load returns the asset from disk. | ||
| func (t *InternalReleaseImageRegistryAuthSecret) Load(f asset.FileFetcher) (bool, error) { | ||
| file, err := f.FetchByName(filepath.Join(content.TemplateDir, internalReleaseImageRegistryAuthSecretFileName)) | ||
| if err != nil { | ||
| if os.IsNotExist(err) { | ||
| return false, nil | ||
| } | ||
| return false, err | ||
| } | ||
| t.FileList = []*asset.File{file} | ||
| return true, nil | ||
| } |
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,98 @@ | ||
| package tls //nolint:revive // pre-existing package name | ||
|
|
||
| import ( | ||
| "context" | ||
| "crypto/rand" | ||
| "encoding/base64" | ||
| "fmt" | ||
|
|
||
| "golang.org/x/crypto/bcrypt" | ||
|
|
||
| features "github.com/openshift/api/features" | ||
| "github.com/openshift/installer/pkg/asset" | ||
| "github.com/openshift/installer/pkg/asset/installconfig" | ||
| "github.com/openshift/installer/pkg/asset/templates/content/manifests" | ||
| ) | ||
|
|
||
| const ( | ||
| // IRIRegistryUsername is the fixed username for IRI registry authentication. | ||
| IRIRegistryUsername = "openshift" | ||
| // PasswordBytes is the number of random bytes to generate for the password (256-bit entropy). | ||
| PasswordBytes = 32 | ||
| ) | ||
|
|
||
| // IRIRegistryAuth is the asset for the IRI registry authentication credentials. | ||
| // This is an in-memory-only asset: credentials are consumed by other assets | ||
| // (operators.go, bootstrap/common.go) but not written to disk. | ||
| // | ||
| // This must NOT write files to the auth/ directory. In agent-based installs, | ||
| // assisted-service moves kubeadmin-password and kubeconfig out of auth/ and | ||
| // then calls os.Remove("auth") to delete the directory. That call fails if | ||
| // any extra files remain, which would break the deployment. See: | ||
| // https://github.com/openshift/assisted-service/blob/89897ade7135/internal/ignition/installmanifests.go#L356 | ||
| type IRIRegistryAuth struct { | ||
| Username string | ||
| Password string //nolint:gosec // this is a credential holder, not a hardcoded secret | ||
| HtpasswdContent string | ||
| } | ||
|
|
||
| var _ asset.WritableAsset = (*IRIRegistryAuth)(nil) | ||
|
|
||
| // Dependencies returns the dependencies for generating IRI registry auth. | ||
| func (a *IRIRegistryAuth) Dependencies() []asset.Asset { | ||
| return []asset.Asset{ | ||
| &installconfig.InstallConfig{}, | ||
| &manifests.InternalReleaseImage{}, | ||
| } | ||
| } | ||
|
|
||
| // Generate generates the IRI registry authentication credentials. | ||
| func (a *IRIRegistryAuth) Generate(ctx context.Context, dependencies asset.Parents) error { | ||
| installConfig := &installconfig.InstallConfig{} | ||
| iri := &manifests.InternalReleaseImage{} | ||
| dependencies.Get(installConfig, iri) | ||
|
|
||
| // Only generate if NoRegistryClusterInstall feature is enabled | ||
| if !installConfig.Config.EnabledFeatureGates().Enabled(features.FeatureGateNoRegistryClusterInstall) { | ||
| return nil | ||
| } | ||
|
|
||
| // Skip if InternalReleaseImage manifest wasn't found | ||
| if len(iri.FileList) == 0 { | ||
| return nil | ||
| } | ||
|
|
||
| // Generate random password (32 bytes = 256-bit entropy) | ||
| passwordBytes := make([]byte, PasswordBytes) | ||
| if _, err := rand.Read(passwordBytes); err != nil { | ||
| return fmt.Errorf("failed to generate random password: %w", err) | ||
| } | ||
| a.Password = base64.StdEncoding.EncodeToString(passwordBytes) | ||
| a.Username = IRIRegistryUsername | ||
|
|
||
| // Create bcrypt hash | ||
| hash, err := bcrypt.GenerateFromPassword([]byte(a.Password), bcrypt.DefaultCost) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to hash password: %w", err) | ||
| } | ||
|
|
||
| // Create htpasswd format: username:bcrypt-hash | ||
| a.HtpasswdContent = fmt.Sprintf("%s:%s\n", a.Username, string(hash)) | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| // Name returns the human-friendly name of the asset. | ||
| func (a *IRIRegistryAuth) Name() string { | ||
| return "IRI Registry Authentication" | ||
| } | ||
|
|
||
| // Files returns an empty list as this is an in-memory-only asset. | ||
| func (a *IRIRegistryAuth) Files() []*asset.File { | ||
| return []*asset.File{} | ||
| } | ||
|
|
||
| // Load returns false as this asset is not persisted to disk. | ||
| func (a *IRIRegistryAuth) Load(f asset.FileFetcher) (bool, error) { | ||
| return false, nil | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
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.
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.
Add nil/empty check before accessing
Files()[0].If
InternalReleaseImageRegistryAuthSecret.Generate()returns early (e.g., feature gate disabled or IRI manifest missing),Files()will return an empty slice. AccessingFiles()[0]would cause a panic. Although the caller checkslen(iri.FileList) > 0, this function should defensively validate its own input.🛡️ Proposed fix to add defensive check
func appendIRIRegistryAuth(dependencies asset.Parents) *asset.File { iriAuth := &tls.IRIRegistryAuth{} iriAuthSecret := &bootkube.InternalReleaseImageRegistryAuthSecret{} dependencies.Get(iriAuth, iriAuthSecret) + files := iriAuthSecret.Files() + if len(files) == 0 { + return nil + } + f := files[0] - f := iriAuthSecret.Files()[0] templateData := struct {Then update the caller to handle nil:
if len(iri.FileList) > 0 { files = append(files, appendIRIcerts(dependencies)) - files = append(files, appendIRIRegistryAuth(dependencies)) + if authFile := appendIRIRegistryAuth(dependencies); authFile != nil { + files = append(files, authFile) + } }📝 Committable suggestion
🤖 Prompt for AI Agents