Skip to content

Commit e133844

Browse files
committed
Improve documentation and add semgrep configuration
1 parent f46350a commit e133844

File tree

8 files changed

+64
-35
lines changed

8 files changed

+64
-35
lines changed

.github/workflows/semgrep.yml

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Name of this GitHub Actions workflow.
2+
name: Semgrep
3+
4+
on:
5+
# Option 1: Scan changed files in PRs, only report new findings (existing
6+
# findings in the repository are ignored).
7+
# To run on specific types of PR states (opened, reopened, etc) or particular
8+
# paths or branches, see the following GitHub documentation:
9+
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request
10+
pull_request: {}
11+
jobs:
12+
semgrep:
13+
# User definable name of this GitHub Actions job.
14+
name: Scan
15+
# Only change the if you are self-hosting. See also:
16+
# https://docs.github.com/en/actions/using-jobs/choosing-the-runner-for-a-job#choosing-self-hosted-runners
17+
runs-on: ubuntu-latest
18+
container:
19+
# A Docker image with Semgrep installed. Don't change this.
20+
image: returntocorp/semgrep
21+
# Skip any PR created by dependabot to avoid permission issues
22+
if: (github.actor != 'dependabot[bot]')
23+
steps:
24+
# Fetch project source with GitHub Actions Checkout.
25+
- uses: actions/checkout@v3
26+
27+
# Run the "semgrep ci" command on the command line of the docker image.
28+
- run: semgrep ci
29+
env:
30+
# Option 2: Set hard-coded rulesets, viewable in logs.
31+
SEMGREP_RULES: p/default # more at semgrep.dev/explore

.semgrepignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Invalid RSA key for testing
2+
tst/certs/invalid-rsa-key.pem

README.md

+24-2
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,41 @@ rolesanywhere-credential-helper implements the [signing process](https://docs.aw
44

55
## Building
66

7-
In order to build the source code, you will need to install a C compiler, along with make and golang. On Debian-based systems, you can do so using `sudo apt-get install build-essential golang-go`. After obtaining these tools, you can build the package (assuming you are currently at the package root):
7+
### Dependencies
8+
9+
In order to build the source code, you will need to install git, a C compiler, make, and golang.
10+
11+
#### Linux
12+
13+
On Debian-based systems, you can do so using `sudo apt-get install git build-essential golang-go`. For other Linux distributions, replace `apt-get` with the package manager on your system.
14+
15+
#### Darwin
16+
17+
You can download Apple clang through the [following link](https://developer.apple.com/download/) if you don't already have it installed on your system. You can install git, make, and golang through Homebrew through `brew install git`, `brew install make` and `brew install go`, respectively.
18+
19+
#### Windows
20+
21+
In order to get a C compile on Windows, one option is to use [MinGW-w64](https://www.mingw-w64.org/downloads/). After obtaining a C compiler, you can install golang through the [installer](https://go.dev/doc/install). Lastly, you can install git and make through `Chocolatey` with `choco install git` and `choco install make`, respectively.
22+
23+
### Build
24+
25+
After obtaining these tools, and making sure they are on your `PATH`, you can build the package (assuming you are currently at the package root):
826

927
```
1028
make release
1129
```
1230

1331
After building, you should see the `aws_signing_helper` binary built for your system at `build/bin/aws_signing_helper`. Usage is discussed briefly in the next section.
1432

33+
### Scripts
34+
35+
The project also comes with two bash scripts at its root, called `generate-certs.sh` and `generate-credential-process-data.sh`. The former script is used strictly for unit testing, and it generates certificate and private key data with different parameters that are supported by IAM Roles Anywhere. You can run the bash script using `/bin/bash generate-certs.sh`, and you will see the generated certificates and keys under the `tst/certs` directory. The latter script is used both for unit testing and can also be used for testing the `credential-process` command after having built the binary. It will create a CA certificate/private key as well as a leaf certificate/private key. When testing IAM Roles Anywhere, you will have to upload the CA certificate a trust anchor and create a profile within Roles Anywhere before using the binary along with the leaf certificate/private key to call `credential-process` (more instructions can be found in the next section). You can run the bash script using `/bin/bash generate-credential-process-data.sh`, and you will see the generated certificate hierarchy (and corresponding keys) under the `credential-process-data` directory. Note that the unit tests that require these fixtures to exist will run the bash script themselves, before executing those tests that depend on the fixtures existing. Please note that these scripts currently only work on Unix-based systems and require `openssl` to be installed.
36+
1537
## Usage
1638

1739
There are three commands that are currently implemented within the source code. Two of these commands, `sign-string` and `read-certificate-data` are given as diagnostic tools. The former command allows one to sign a string that comes from standard input. The command requires one to pass in the path of a private key on disk to perform the signing (`--private-key`), as well as two optional arguments for the digest (`--digest`) and output format (`--format`). The digest has to be one of `SHA256`, `SHA384`, and `SHA512` if specified. The default value will be `SHA256` if it isn't specified. The output format has to be one of `text`, `json`, and `bin` if specified. The default value will be `text` if it isn't specified. The latter command allows one to read a certificate that is on disk. The path to the certificate (`--certificate`) is required.
1840

19-
The last command is `credential-process`, which returns temporary credentials in a JSON format that is compatible with the `credential_process` feature available across language SDKs. Documentation on usage, along with examples can be found [here](https://docs.aws.amazon.com/rolesanywhere/latest/userguide/credential-helper.html). A script called `generate-credential-process-data.sh` can be found at the root of the project, which will generate RSA private keys and their corresponding certificates, that you can use to obtain temporary credentials from IAM Roles Anywhere. You can run the script using `/bin/bash generate-credential-process-data.sh`. Afterwards, you should see the generated private keys and certificates under the `credential-process-data` directory. The following example showcases how to use the data to obtain temporary credentials:
41+
The last command is `credential-process`, which returns temporary credentials in a JSON format that is compatible with the `credential_process` feature available across language SDKs. Documentation on usage, along with examples can be found [here](https://docs.aws.amazon.com/rolesanywhere/latest/userguide/credential-helper.html). A script called `generate-credential-process-data.sh` can be found at the root of the project, which will generate RSA private keys and their corresponding certificates, that you can use to obtain temporary credentials from IAM Roles Anywhere. You can run the script using `/bin/bash generate-credential-process-data.sh`. Afterwards, you should see the generated private keys and certificates under the `credential-process-data` directory. The following example showcases how to use the data to obtain temporary credentials (assuming you are on a unix-based system):
2042

2143
```
2244
TA_ARN=$(aws rolesanywhere create-trust-anchor \

aws_signing_helper/credentials.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,12 @@ func GenerateCredentials(opts *CredentialsOpts) (CredentialProcessOutput, error)
9090
var tr *http.Transport
9191
if opts.WithProxy {
9292
tr = &http.Transport{
93-
TLSClientConfig: &tls.Config{InsecureSkipVerify: opts.NoVerifySSL},
93+
TLSClientConfig: &tls.Config{MinVersion: tls.VersionTLS13, InsecureSkipVerify: opts.NoVerifySSL},
9494
Proxy: http.ProxyFromEnvironment,
9595
}
9696
} else {
9797
tr = &http.Transport{
98-
TLSClientConfig: &tls.Config{InsecureSkipVerify: opts.NoVerifySSL},
98+
TLSClientConfig: &tls.Config{MinVersion: tls.VersionTLS13, InsecureSkipVerify: opts.NoVerifySSL},
9999
}
100100
}
101101
client := &http.Client{Transport: tr}

aws_signing_helper/signer_test.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,7 @@ func setup() error {
3232

3333
generateCredentialProcessDataScript := exec.Command("/bin/bash", "../generate-credential-process-data.sh")
3434
_, err = generateCredentialProcessDataScript.Output()
35-
if err != nil {
36-
return err
37-
}
38-
39-
return nil
35+
return err
4036
}
4137

4238
func TestMain(m *testing.M) {

tst/certs/cert-bundle.pem

-26
This file was deleted.

tst/certs/invalid-rsa-cert.pem

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
Note: This is a certificate that can't be parsed.
2+
13
-----BEGIN CERTIFICATE-----
24
MIID2DCCAsCgAwIBAgIRAKsybXibFSiZYcGp+Q6O804wDQYJKoZIhvcNAQELBQAw
35
XzELMAkGA1UEBhMCVVMxHDAaBgNVBAoME1NlY3VyaXR5IElubm92YXRpb24xEDAO

tst/certs/invalid-rsa-key.pem

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
Note: this is a RSA private key that can't be parsed.
2+
13
-----BEGIN RSA PRIVATE KEY-----
24
MIIEowIBAAKCAQEA1UtA1UjG/fhjhGEsQ3dAwacylFxlnbF+Q1Se0KhxZiuI8z2r
35
MFEpv5/16fe38hNI/lQFYLime2+89ZnmDXj0bcrLyeUSaXBXHKhTSqx9akllU6r7

0 commit comments

Comments
 (0)