-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added containerd support Context: Since kubernetes 1.25 docker is being removed as the default container runtime in favor of containerd. Due this is desired to have a mechanism to parse containerd auth files following the spec defined here: https://github.com/containerd/containerd/blob/main/docs/cri/config.md#registry-configuration On this PR is being implemented the necesary code to parse the containerd toml files and login on the registries defined on them. Change-Id: Ic38ad5ba981cbea32aa2dd2aecd312409f5516a2 Co-authored-by: Javier Avila <[email protected]> Co-developed-by: Javier Avila <[email protected]> * fixup! Added containerd support * fixup! Added containerd support --------- Co-authored-by: Javier Avila <[email protected]>
- Loading branch information
1 parent
28dfe3e
commit ad52603
Showing
7 changed files
with
514 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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,77 @@ | ||
package registry | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/pelletier/go-toml" | ||
"github.com/spf13/afero" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestAuthenticateWithimagePullSecret(t *testing.T) { | ||
imagePullSecret := `{"auths":{"registry.example.com":{"username":"user","password":"pass","auth":"YXV0aDp1c2VyOnBhc3M="}}}` | ||
registry := "registry.example.com" | ||
image := "myimage" | ||
tag := "latest" | ||
|
||
authenticator := RegistryAuthenticator{fs: afero.NewMemMapFs()} // Create an instance of the RegistryAuthenticator | ||
|
||
candidates := authenticator.Authenticate(context.Background(), imagePullSecret, registry, image, tag) | ||
|
||
receivedToken, ok := <-candidates | ||
assert.True(t, ok, "AuthenticationToken not received") | ||
|
||
expectedToken := AuthenticationToken{ | ||
Kind: "Basic", | ||
Token: "YXV0aDp1c2VyOnBhc3M=", | ||
} | ||
|
||
assert.Equal(t, expectedToken, receivedToken) | ||
|
||
} | ||
|
||
func TestRegistryAuthenticator_GetHeaderOnContainerdFiles(t *testing.T) { | ||
fs := afero.NewMemMapFs() | ||
|
||
// Create test directory and files in the in-memory file system | ||
err := fs.MkdirAll("/etc/containerd", 0755) | ||
assert.NoError(t, err) | ||
|
||
config := ContainerdConfig{ | ||
Server: "registry.example.com", | ||
Hosts: map[string]ContainerdHostConfig{ | ||
"example-host": { | ||
Capabilities: []string{"cap1", "cap2"}, | ||
Header: ContainerdHeader{ | ||
Authorization: "Basic dXNlcjpwYXNz", | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
configData, err := toml.Marshal(config) | ||
assert.NoError(t, err) | ||
|
||
err = afero.WriteFile(fs, "/etc/containerd/config.toml", configData, 0644) | ||
assert.NoError(t, err) | ||
|
||
authenticator := RegistryAuthenticator{fs: fs} // Create an instance of the RegistryAuthenticator | ||
|
||
imagePullSecret := "" | ||
registry := "registry.example.com" | ||
image := "myimage" | ||
tag := "latest" | ||
|
||
candidates := authenticator.Authenticate(context.Background(), imagePullSecret, registry, image, tag) | ||
|
||
receivedToken, ok := <-candidates | ||
assert.True(t, ok, "AuthenticationToken not received") | ||
|
||
expectedToken := AuthenticationToken{ | ||
Kind: "Basic", | ||
Token: "dXNlcjpwYXNz", | ||
} | ||
|
||
assert.Equal(t, expectedToken, receivedToken) | ||
} |
This file contains 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