-
Notifications
You must be signed in to change notification settings - Fork 32
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
certificate propagation throughout the build process #647
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* | ||
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. Same as the comment above, can we remove this file and directory. EIB configurations should be done only from EIB's image configuration directory. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,12 +14,12 @@ import ( | |
) | ||
|
||
type mockRPMResolver struct { | ||
resolveFunc func(packages *image.Packages, localRPMConfig *image.LocalRPMConfig, outputDir string) (rpmDir string, pkgList []string, err error) | ||
resolveFunc func(packages *image.Packages, localRPMConfig *image.LocalRPMConfig, certsPath, outputDir string) (rpmDir string, pkgList []string, err error) | ||
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. This change needs to be reflected in the |
||
} | ||
|
||
func (m mockRPMResolver) Resolve(packages *image.Packages, localRPMConfig *image.LocalRPMConfig, outputDir string) (rpmDir string, pkgList []string, err error) { | ||
func (m mockRPMResolver) Resolve(packages *image.Packages, localRPMConfig *image.LocalRPMConfig, certsPath, outputDir string) (rpmDir string, pkgList []string, err error) { | ||
if m.resolveFunc != nil { | ||
return m.resolveFunc(packages, localRPMConfig, outputDir) | ||
return m.resolveFunc(packages, localRPMConfig, certsPath, outputDir) | ||
} | ||
|
||
panic("not implemented") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,7 +81,7 @@ func New(workDir string, podman Podman, baseImageBuilder BaseResolverImageBuilde | |
// - localRPMConfig - configuration for locally provided RPMs | ||
// | ||
// - outputDir - directory in which the resolver will create a directory containing the resolved rpms. | ||
func (r *Resolver) Resolve(packages *image.Packages, localRPMConfig *image.LocalRPMConfig, outputDir string) (rpmDirPath string, pkgList []string, err error) { | ||
func (r *Resolver) Resolve(packages *image.Packages, localRPMConfig *image.LocalRPMConfig, certsPath, outputDir string) (rpmDirPath string, pkgList []string, err error) { | ||
zap.L().Info("Resolving package dependencies...") | ||
|
||
revert, err := mount.DisableDefaultMounts(r.overrideMountsPath) | ||
|
@@ -98,7 +98,7 @@ func (r *Resolver) Resolve(packages *image.Packages, localRPMConfig *image.Local | |
return "", nil, fmt.Errorf("building base resolver image: %w", err) | ||
} | ||
|
||
if err = r.prepare(localRPMConfig, packages); err != nil { | ||
if err = r.prepare(localRPMConfig, packages, certsPath); err != nil { | ||
return "", nil, fmt.Errorf("generating context for the resolver image: %w", err) | ||
} | ||
|
||
|
@@ -122,7 +122,7 @@ func (r *Resolver) Resolve(packages *image.Packages, localRPMConfig *image.Local | |
return filepath.Join(outputDir, rpmRepoName), r.generatePKGInstallList(packages), nil | ||
} | ||
|
||
func (r *Resolver) prepare(localRPMConfig *image.LocalRPMConfig, packages *image.Packages) error { | ||
func (r *Resolver) prepare(localRPMConfig *image.LocalRPMConfig, packages *image.Packages, certsPath string) error { | ||
zap.L().Info("Preparing resolver image context...") | ||
|
||
buildContext := r.generateBuildContextPath() | ||
|
@@ -136,6 +136,10 @@ func (r *Resolver) prepare(localRPMConfig *image.LocalRPMConfig, packages *image | |
} | ||
} | ||
|
||
if err := r.prepareCertificates(certsPath); err != nil { | ||
return fmt.Errorf("preparing certificates for resolver image build: %w", err) | ||
} | ||
|
||
if err := r.writeRPMResolutionScript(localRPMConfig, packages); err != nil { | ||
return fmt.Errorf("writing rpm resolution script: %w", err) | ||
} | ||
|
@@ -148,6 +152,29 @@ func (r *Resolver) prepare(localRPMConfig *image.LocalRPMConfig, packages *image | |
return nil | ||
} | ||
|
||
func (r *Resolver) prepareCertificates(certsPath string) error { | ||
certsDest := r.generateCertificatePathInBuildContext() | ||
|
||
if err := os.MkdirAll(certsDest, os.ModePerm); err != nil { | ||
return fmt.Errorf("creating certificates dir %s: %w", certsDest, err) | ||
} | ||
|
||
if _, err := os.Stat(certsPath); os.IsNotExist(err) { | ||
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. I suggest moving the validation before the actual Also we could probably use the existing fileio.FileExists function here. |
||
zap.S().Info("skipping certificates, no certificates provided") | ||
return nil | ||
} | ||
|
||
if err := fileio.CopyFiles(certsPath, certsDest, ".crt", false, &fileio.NonExecutablePerms); err != nil { | ||
return fmt.Errorf("copying crt files to %s: %w", certsDest, err) | ||
} | ||
|
||
if err := fileio.CopyFiles(certsPath, certsDest, ".pem", false, &fileio.NonExecutablePerms); err != nil { | ||
return fmt.Errorf("copying pem files to %s: %w", certsDest, err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (r *Resolver) prepareLocalRPMs(localRPMConfig *image.LocalRPMConfig) error { | ||
rpmDest := r.generateRPMPathInBuildContext() | ||
if err := fileio.CopyFiles(localRPMConfig.RPMPath, rpmDest, ".rpm", false, &fileio.NonExecutablePerms); err != nil { | ||
|
@@ -274,6 +301,11 @@ func (r *Resolver) generateBuildContextPath() string { | |
return filepath.Join(r.dir, "resolver-image-build") | ||
} | ||
|
||
// path to the certificates directory in the resolver build context, as seen in the EIB image | ||
func (r *Resolver) generateCertificatePathInBuildContext() string { | ||
return filepath.Join(r.generateBuildContextPath(), "certificates") | ||
} | ||
|
||
// path to the rpms directory in the resolver build context, as seen in the EIB image | ||
func (r *Resolver) generateRPMPathInBuildContext() string { | ||
return filepath.Join(r.generateBuildContextPath(), "rpms") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,8 @@ COPY {{ .FromGPGPath }} {{ .ToGPGPath }} | |
{{ end -}} | ||
{{ end }} | ||
|
||
COPY certificates/. /etc/pki/trust/anchors/ | ||
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. I'd suggest to avoid hardcoding the path to the |
||
|
||
RUN ./{{ .RPMResolutionScriptName }} | ||
|
||
CMD ["/bin/bash"] |
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.
There is no need to add the certificates as part of the EIB Dockerfile itself. The EIB Dockerfile is running a fixed set of configurations that are proven to successfully build an EIB container image.
Any configurations for EIB or its underlying RPM resolution process must be done only from EIB's image configuration directory.
Based on this I suggest we remove the certificate inclusion from here.
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.
In my environment, the outgoing traffic is reencrypted at the edge and monitored, that means I have a cert that I need to add to the trust for building of the base EIB image. When using the upstream image it is pretty simple to just add my needed certs though.
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.
basically an accepted MITM :)