Skip to content

Commit

Permalink
Reject the -toolexec flag (ko-build#752)
Browse files Browse the repository at this point in the history
  • Loading branch information
imjasonh authored Jul 13, 2022
1 parent ca1648d commit d108e69
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pkg/build/gobuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,16 @@ func createBuildArgs(buildCfg Config) ([]string, error) {
args = append(args, fmt.Sprintf("-ldflags=%s", strings.Join(buildCfg.Ldflags, " ")))
}

// Reject any flags that attempt to set --toolexec (with or
// without =, with one or two -s)
for _, a := range args {
for _, d := range []string{"-", "--"} {
if a == d+"toolexec" || strings.HasPrefix(a, d+"toolexec=") {
return nil, fmt.Errorf("cannot set %s", a)
}
}
}

return args, nil
}

Expand Down
6 changes: 6 additions & 0 deletions test/build-configs/.ko.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,9 @@ builds:
- id: bar-app
dir: ./bar
main: ./cmd
- id: toolexec
dir: ./toolexec
main: ./cmd
flags:
- -toolexec
- go
21 changes: 21 additions & 0 deletions test/build-configs/toolexec/cmd/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2022 Google LLC All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package main

import "fmt"

func main() {
fmt.Println("toolexec")
}
17 changes: 17 additions & 0 deletions test/build-configs/toolexec/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright 2022 Google LLC All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

module example.com/toolexec

go 1.16

0 comments on commit d108e69

Please sign in to comment.