Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ members = [
"packages/e2fsprogs",
"packages/early-boot-config",
"packages/ecr-credential-helper",
"packages/ecr-credential-helper-shim",
"packages/ecr-credential-provider-1.29",
"packages/ecr-credential-provider-1.30",
"packages/ecr-credential-provider-1.31",
Expand Down
1 change: 1 addition & 0 deletions kits/bottlerocket-core-kit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ docker-init = { path = "../../packages/docker-init" }
e2fsprogs = { path = "../../packages/e2fsprogs" }
early-boot-config = { path = "../../packages/early-boot-config" }
ecr-credential-helper = { path = "../../packages/ecr-credential-helper" }
ecr-credential-helper-shim = { path = "../../packages/ecr-credential-helper-shim" }
ecr-credential-provider-1_29 = { path = "../../packages/ecr-credential-provider-1.29" }
ecr-credential-provider-1_30 = { path = "../../packages/ecr-credential-provider-1.30" }
ecr-credential-provider-1_31 = { path = "../../packages/ecr-credential-provider-1.31" }
Expand Down
15 changes: 15 additions & 0 deletions packages/ecr-credential-helper-shim/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you clarify why a new package rather than using the OS package?

name = "ecr-credential-helper-shim"
version = "0.1.0"
edition = "2021"
publish = false
build = "../build.rs"

[package.metadata.build-package]
source-groups = [ "ecr-credential-helper-shim" ]

[lib]
path = "../packages.rs"

[build-dependencies]
glibc = { path = "../glibc" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
%global _cross_first_party 1
%undefine _debugsource_packages

Name: %{_cross_os}ecr-credential-helper-shim
Version: 0.1.0
Release: 1%{?dist}
Summary: FIPS shim for ECR credential helper
License: Apache-2.0 OR MIT
URL: https://github.com/bottlerocket-os/bottlerocket
BuildRequires: %{_cross_os}glibc-devel

%description
%{summary}.

%prep
%setup -T -c
%cargo_prep

%build
%cargo_build --manifest-path %{_builddir}/sources/Cargo.toml \
-p ecr-credential-helper-shim \
--target-dir=${HOME}/.cache/ecr-credential-helper-shim

%install
install -d %{buildroot}%{_cross_bindir}
install -p -m 0755 ${HOME}/.cache/ecr-credential-helper-shim/%{__cargo_target}/release/ecr-credential-helper-shim %{buildroot}%{_cross_bindir}/docker-credential-ecr-login

%files
%{_cross_bindir}/docker-credential-ecr-login
10 changes: 4 additions & 6 deletions packages/ecr-credential-helper/ecr-credential-helper.spec
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
%global _dwz_low_mem_die_limit 0

Name: %{_cross_os}ecr-credential-helper
Requires: %{_cross_os}ecr-credential-helper-shim
Version: %{rpmver}
Release: 1%{?dist}
Summary: Amazon ECR credential helper
Expand All @@ -31,14 +32,12 @@ BuildRequires: %{_cross_os}glibc-devel
%cross_go_setup %{gorepo}-%{gover} %{goproject} %{goimport}

%build
# cross_go_configure cd's to the correct GOPATH location
%cross_go_configure %{goimport}

go build -ldflags="${GOLDFLAGS}" -o=docker-credential-ecr-login ./ecr-login/cli/docker-credential-ecr-login

%install
install -d %{buildroot}%{_cross_bindir}
install -p -m 0755 docker-credential-ecr-login %{buildroot}%{_cross_bindir}
install -d %{buildroot}%{_cross_libexecdir}
install -p -m 0755 docker-credential-ecr-login %{buildroot}%{_cross_libexecdir}

install -d %{buildroot}%{_cross_tmpfilesdir}
install -p -m0644 %{S:10} %{buildroot}%{_cross_tmpfilesdir}/ecr-credential-helper.conf
Expand All @@ -55,9 +54,8 @@ install -p -m0600 %{S:13} %{buildroot}%{_cross_factorydir}/root/.docker/config.j
%license LICENSE
%{_cross_attribution_file}
%{_cross_attribution_vendor_dir}
%{_cross_bindir}/docker-credential-ecr-login
%{_cross_libexecdir}/docker-credential-ecr-login
%{_cross_factorydir}/root/.docker/config.json
%{_cross_tmpfilesdir}/ecr-credential-helper.conf
%{_cross_unitdir}/root-.docker.mount
%{_cross_unitdir}/root-.ecr.mount

4 changes: 4 additions & 0 deletions sources/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions sources/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ members = [
"xfscli",

"whippet",

"ecr-credential-helper-shim",
]

[workspace.dependencies]
Expand Down
11 changes: 11 additions & 0 deletions sources/ecr-credential-helper-shim/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

[package]
name = "ecr-credential-helper-shim"
version = "0.1.0"
authors = ["Jingwei Wang <jweiw@amazon.com>"]
license = "Apache-2.0 OR MIT"
edition = "2021"
publish = false
# Don't rebuild crate just because of changes to README.
exclude = ["README.md"]

21 changes: 21 additions & 0 deletions sources/ecr-credential-helper-shim/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use std::env;
use std::process::{self, Command};

fn main() {
let godebug = env::var("GODEBUG")
.unwrap_or_default()
.replace("fips140=only", "fips140=on");

let status = Command::new("/usr/libexec/docker-credential-ecr-login")
.args(env::args().skip(1))
.env("GODEBUG", &godebug)
.status();
Comment on lines +9 to +12
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than executing the call of the helper in a separate process (fork), you should exec the call instead:

https://www.man7.org/linux/man-pages/man3/exec.3.html

So that you don't have to capture the status, and you don't have to worry about handling STDOUT/STDERR in case they require special handling by whatever is calling your shim.


match status {
Ok(s) => process::exit(s.code().unwrap_or(1)),
Err(err) => {
eprintln!("Failed to exec /usr/libexec/docker-credential-ecr-login: {err}");
process::exit(1);
}
}
}
1 change: 1 addition & 0 deletions sources/notation-image-verifier/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func main() {
// Bottlerocket does not have a $HOME set by default and notation expect to find
// credentials from the ecr-credential-helper here.
os.Setenv("HOME", "/root")
os.Setenv("GODEBUG", "fips140=on")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will notation break if fips140=only? Or did you do this to guarantee that the notation process that calls your shim also enforces fips140=on? If the only thing that breaks is the ECR helper, this shouldn't be needed.


cmd := exec.Command("notation", "verify", imageRef)
output, err := cmd.CombinedOutput()
Expand Down