Skip to content
Merged
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
21 changes: 17 additions & 4 deletions internal/tools/securitypolicy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,26 @@ TOML configuration file to process (required)

output raw JSON in addition to the Base64 encoded version

- -u
## Authorization

username to use to login to remote container services (defaults to anonymous)
Some images will be pulled from registries that require authorization. To add
authorization information for a given image, you would add an `[auth]` object
to the TOML definiton for that image. For example:

- -p
```toml
[[image]]
name = "rust:1.52.1"
command = ["rustc", "--help"]

[auth]
username = "my username"
password = "my password"
```

Authorization information needs added on a per-image basis as it can vary from
image to image and their respective registries.

password to use to login to remote container services (defaults to anonymous)
To pull an image using anonymous access, no `[auth]` object is required.

## Pause container

Expand Down
29 changes: 17 additions & 12 deletions internal/tools/securitypolicy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ import (
var (
configFile = flag.String("c", "", "config")
outputJSON = flag.Bool("j", false, "json")
username = flag.String("u", "", "username")
password = flag.String("p", "", "password")
)

func main() {
Expand Down Expand Up @@ -87,10 +85,16 @@ type EnvironmentVariableRule struct {

type Image struct {
Name string `toml:"name"`
Auth ImageAuth `toml:"auth"`
Command []string `toml:"command"`
EnvRules []EnvironmentVariableRule `toml:"env_rule"`
}

type ImageAuth struct {
Username string `toml:"username"`
Password string `toml:"password"`
}

type Config struct {
AllowAll bool `toml:"allow_all"`
Images []Image `toml:"image"`
Expand All @@ -107,16 +111,6 @@ func createPolicyFromConfig(config Config) (sp.SecurityPolicy, error) {
Containers: map[string]sp.SecurityPolicyContainer{},
}

var imageOptions []remote.Option
if len(*username) != 0 && len(*password) != 0 {
auth := authn.Basic{
Username: *username,
Password: *password}
c, _ := auth.Authorization()
authOption := remote.WithAuth(authn.FromConfig(*c))
imageOptions = append(imageOptions, authOption)
}

// Hardcode the pause container version and command. We still pull it
// to get the root hash and any environment variable rules we might need.
pause := Image{
Expand All @@ -126,6 +120,17 @@ func createPolicyFromConfig(config Config) (sp.SecurityPolicy, error) {
config.Images = append(config.Images, pause)

for _, image := range config.Images {
var imageOptions []remote.Option

if image.Auth.Username != "" && image.Auth.Password != "" {
auth := authn.Basic{
Username: image.Auth.Username,
Password: image.Auth.Password}
c, _ := auth.Authorization()
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.

Was wondering why this was ignored, but turns out it just returns nil always 😂.

authOption := remote.WithAuth(authn.FromConfig(*c))
imageOptions = append(imageOptions, authOption)
}

// validate EnvRules
err := validateEnvRules(image.EnvRules)
if err != nil {
Expand Down