Skip to content

Commit

Permalink
report error using non-file secret|config with read-only service
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas De Loof <[email protected]>
  • Loading branch information
ndeloof committed Feb 6, 2025
1 parent 6ecb8d4 commit 5cc9da5
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions pkg/compose/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ func (s *composeService) injectSecrets(ctx context.Context, project *types.Proje
continue
}

if service.ReadOnly {
return fmt.Errorf("cannot create secret %q in read-only service %s: `file` is the sole supported option", file.Name, service.Name)
}

if config.Target == "" {
config.Target = "/run/secrets/" + config.Source
} else if !isAbsTarget(config.Target) {
Expand All @@ -43,7 +47,7 @@ func (s *composeService) injectSecrets(ctx context.Context, project *types.Proje

env, ok := project.Environment[file.Environment]
if !ok {
return fmt.Errorf("environment variable %q required by file %q is not set", file.Environment, file.Name)
return fmt.Errorf("environment variable %q required by secret %q is not set", file.Environment, file.Name)
}
b, err := createTar(env, types.FileReferenceConfig(config))
if err != nil {
Expand All @@ -67,14 +71,18 @@ func (s *composeService) injectConfigs(ctx context.Context, project *types.Proje
if file.Environment != "" {
env, ok := project.Environment[file.Environment]
if !ok {
return fmt.Errorf("environment variable %q required by file %q is not set", file.Environment, file.Name)
return fmt.Errorf("environment variable %q required by config %q is not set", file.Environment, file.Name)
}
content = env
}
if content == "" {
continue
}

if service.ReadOnly {
return fmt.Errorf("cannot create config %q in read-only service %s: `file` is the sole supported option", file.Name, service.Name)
}

if config.Target == "" {
config.Target = "/" + config.Source
}
Expand Down

0 comments on commit 5cc9da5

Please sign in to comment.