Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

Commit

Permalink
Merge pull request #4 from etter-tanium/support-entitlements
Browse files Browse the repository at this point in the history
Add support for signing with an Entitlements file
  • Loading branch information
mitchellh committed Nov 6, 2019
2 parents 69049d8 + 861a622 commit 0723683
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 13 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ Supported configurations:
flag for the `codesign` binary on macOS. See `man codesign` for detailed
documentation on accepted values.

* `entitlements_file` (`string` _optional_) - The full path to a plist format .entitlements file, used for the `--entitlements` argument to `codesign`

* `dmg` (_optional_) - Settings related to creating a disk image (dmg) as output.
This will only be created if this is specified. The dmg will also have the
notarization ticket stapled so that it can be verified offline and
Expand Down Expand Up @@ -378,5 +380,3 @@ These are some things I'd love to see but aren't currently implemented.
- The underlying script we use already supports this.
* Support adding additional files to the zip, dmg packages
* Support the creation of '.app' bundles for CLI applications
* Support entitlements for codesigning

7 changes: 4 additions & 3 deletions cmd/gon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,10 @@ func realMain() int {
// Perform codesigning
color.New(color.Bold).Fprintf(os.Stdout, "==> %s Signing files...\n", iconSign)
err = sign.Sign(context.Background(), &sign.Options{
Files: cfg.Source,
Identity: cfg.Sign.ApplicationIdentity,
Logger: logger.Named("sign"),
Files: cfg.Source,
Identity: cfg.Sign.ApplicationIdentity,
Entitlements: cfg.Sign.EntitlementsFile,
Logger: logger.Named("sign"),
})
if err != nil {
fmt.Fprintf(os.Stdout, color.RedString("❗️ Error signing files:\n\n%s\n", err))
Expand Down
4 changes: 3 additions & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type AppleId struct {
Provider string `hcl:"provider,optional"`
}

// NOtarize are the options for notarizing a pre-built file.
// Notarize are the options for notarizing a pre-built file.
type Notarize struct {
// Path is the path to the file to notarize. This can be any supported
// filetype (dmg, pkg, app, zip).
Expand All @@ -66,6 +66,8 @@ type Sign struct {
// ApplicationIdentity is the ID or name of the certificate to
// use for signing binaries. This is used for all binaries in "source".
ApplicationIdentity string `hcl:"application_identity"`
// Specify a path to an entitlements file in plist format
EntitlementsFile string `hcl:"entitlements_file,optional"`
}

// Dmg are the options for a dmg file as output.
Expand Down
12 changes: 12 additions & 0 deletions internal/config/testdata/entitle.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
source = ["./terraform"]
bundle_id = "com.mitchellh.test.terraform"

apple_id {
username = "mitchellh@example.com"
password = "hello"
}

sign {
application_identity = "foo"
entitlements_file = "/path/to/example.entitlements"
}
4 changes: 2 additions & 2 deletions internal/config/testdata/notarize.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ source = []
bundle_id = "com.example.terraform"

notarize {
path = "/path/to/terraform.pkg"
bundle_id = "foo.bar"
path = "/path/to/terraform.pkg"
bundle_id = "foo.bar"
}

apple_id {
Expand Down
10 changes: 5 additions & 5 deletions internal/config/testdata/notarize_multiple.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ source = []
bundle_id = ""

notarize {
path = "/path/to/terraform.pkg"
bundle_id = "foo.bar"
path = "/path/to/terraform.pkg"
bundle_id = "foo.bar"
}

notarize {
path = "/path/to/terraform.pkg"
bundle_id = "foo.bar"
staple = true
path = "/path/to/terraform.pkg"
bundle_id = "foo.bar"
staple = true
}

apple_id {
Expand Down
7 changes: 7 additions & 0 deletions sign/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ type Options struct {
// be in a variety of forms.
Identity string

// Entitlements is an (optional) path to a plist format .entitlements file
Entitlements string

// Output is an io.Writer where the output of the command will be written.
// If this is nil then the output will only be sent to the log (if set)
// or in the error result value if signing failed.
Expand Down Expand Up @@ -68,6 +71,10 @@ func Sign(ctx context.Context, opts *Options) error {
"--options", "runtime",
}

if len(opts.Entitlements) > 0 {
cmd.Args = append(cmd.Args, "--entitlements", opts.Entitlements)
}

// Append the files that we want to sign
cmd.Args = append(cmd.Args, opts.Files...)

Expand Down

0 comments on commit 0723683

Please sign in to comment.