Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sg integrationtest add AZ #369

Merged
merged 37 commits into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
1978a60
sg-integrationtest-includebaker add baking operations to allow policy…
May 17, 2023
9c23e50
sg-integrationtest add block operation
May 17, 2023
1210739
sg-integrationtest add aws kms test and simple signatory-cli test
May 23, 2023
621da68
sg-integrationtest missed workflow changes last commit
May 23, 2023
a3171ff
sg-integrationtest revert config file
May 24, 2023
cb2fcf2
Merge branch 'main' into sg-integrationtest-addcli
May 24, 2023
33e007f
sg-integrationtest improve readme
May 24, 2023
f1c77a5
sg-integrationtest fix aws vault test
May 25, 2023
6cee403
sg-integrationtest add gcp vault
May 26, 2023
fbeaf77
sg-integration-addgcp missed files
May 26, 2023
6c33884
sg-integrationtest-addgcp fix workflow, forgot semicolon
May 27, 2023
c6fc7b7
sg-integrationtest add to gitignore integration_test stuffs
May 29, 2023
d8e510c
sg-intgrationtest add AZ vault
May 30, 2023
5431f78
sg-integrationtest add AZ vault test
May 30, 2023
80c5779
Merge branch 'main' into sg-integrationtest-addaz
May 30, 2023
e374f93
sg-integrationtest add AZ missed merge conflict resolution
May 30, 2023
567cda3
sg-integrationtest add AZ, fix path in workflow
May 30, 2023
407db23
sg-integrationtest add debug for troubleshoot workflow
May 30, 2023
72e1357
debugging AZ vault
May 30, 2023
bda2ced
debug integration test
May 30, 2023
976b088
debug integration test
May 30, 2023
81396f1
debug integration test
May 30, 2023
e76adac
debug integration test
May 30, 2023
60e483a
debug integration test
May 30, 2023
716c262
debug integration test
May 30, 2023
aac23a6
debug integration test
May 30, 2023
322cb84
debug integration test
May 30, 2023
d142dab
debug integration test
May 30, 2023
079bbe8
debug integration test
May 30, 2023
2984618
debug integration test
May 30, 2023
559455d
debug integration test add ssh
May 30, 2023
0f1b7c2
debug integration test add ssh
May 30, 2023
fa92106
debug integration test
May 31, 2023
c8761f1
debug AZ vault - use base64 encoded secret
May 31, 2023
e41e0ff
debug AZ vault - fix path in workflow
May 31, 2023
161fb05
restore build file after debugging. add to info to README
May 31, 2023
4aafa69
sg-integrationtest-addaz use base64 encoded key on workstation, too.
May 31, 2023
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
10 changes: 10 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,15 @@ jobs:
VAULT_AWS_REGION: ${{ secrets.INTEGRATIONTEST_VAULT_AWS_REGION }}
VAULT_AWS_PKH_TZ2: ${{ secrets.INTEGRATIONTEST_VAULT_AWS_TZ2 }}
VAULT_AWS_PKH_TZ3: ${{ secrets.INTEGRATIONTEST_VAULT_AWS_TZ3 }}
VAULT_AZ_CLIENTCERTTHUMB: ${{ secrets.INTEGRATIONTEST_VAULT_AZ_CLIENTCERTTHUMB }}
VAULT_AZ_CLIENTID: ${{ secrets.INTEGRATIONTEST_VAULT_AZ_CLIENTID }}
VAULT_AZ_RESGROUP: ${{ secrets.INTEGRATIONTEST_VAULT_AZ_RESGROUP }}
VAULT_AZ_SP_KEY: ${{ secrets.INTEGRATIONTEST_VAULT_AZ_SP_KEY }}
VAULT_AZ_SUBID: ${{ secrets.INTEGRATIONTEST_VAULT_AZ_SUBID }}
VAULT_AZ_TENANTID: ${{ secrets.INTEGRATIONTEST_VAULT_AZ_TENANTID }}
VAULT_AZ_VAULT: ${{ secrets.INTEGRATIONTEST_VAULT_AZ_VAULT }}
VAULT_AZ_TZ2: ${{ secrets.INTEGRATIONTEST_VAULT_AZ_TZ2 }}
VAULT_AZ_TZ3: ${{ secrets.INTEGRATIONTEST_VAULT_AZ_TZ3 }}
VAULT_GCP_PROJECTID: ${{ secrets.INTEGRATIONTEST_VAULT_GCP_PROJECTID }}
VAULT_GCP_PRIVATEKEYID: ${{ secrets.INTEGRATIONTEST_VAULT_GCP_PRIVATEKEYID }}
VAULT_GCP_PRIVATEKEY: ${{ secrets.INTEGRATIONTEST_VAULT_GCP_PRIVATEKEY }}
Expand All @@ -141,6 +150,7 @@ jobs:
run: >
. integration_test/.env.${{ matrix.testenvs }};
envsubst < integration_test/gcp-token-template.json > integration_test/gcp-token.json;
echo $VAULT_AZ_SP_KEY |base64 -d >integration_test/service-principal.key;
docker compose -f integration_test/docker-compose.yml up -d --wait --pull always;
docker exec octez sudo chown -R tezos /home/tezos/.tezos-client;
go test $(go list ./... | grep integration_test);
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ signatory-cli
# some integration_tests write secret env var to files
integration_test/gcp-token.json
integration_test/.env.vaults.cicd
integration_test/service-principal.key
10 changes: 10 additions & 0 deletions integration_test/.env.vaults
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ export VAULT_AWS_REGION=${{ secrets.INTEGRATIONTEST_VAULT_AWS_REGION }}
export VAULT_AWS_PKH_TZ2=${{ secrets.INTEGRATIONTEST_VAULT_AWS_TZ2 }}
export VAULT_AWS_PKH_TZ3=${{ secrets.INTEGRATIONTEST_VAULT_AWS_TZ3 }}

export VAULT_AZ_CLIENTCERTTHUMB=${{ secrets.INTEGRATIONTEST_VAULT_AZ_CLIENTCERTTHUMB }}
export VAULT_AZ_CLIENTID=${{ secrets.INTEGRATIONTEST_VAULT_AZ_CLIENTID }}
export VAULT_AZ_RESGROUP=${{ secrets.INTEGRATIONTEST_VAULT_AZ_RESGROUP }}
export VAULT_AZ_SP_KEY=${{ secrets.INTEGRATIONTEST_VAULT_AZ_SP_KEY }}
export VAULT_AZ_SUBID=${{ secrets.INTEGRATIONTEST_VAULT_AZ_SUBID }}
export VAULT_AZ_TENANTID=${{ secrets.INTEGRATIONTEST_VAULT_AZ_TENANTID }}
export VAULT_AZ_VAULT=${{ secrets.INTEGRATIONTEST_VAULT_AZ_VAULT }}
export VAULT_AZ_TZ2=${{ secrets.INTEGRATIONTEST_VAULT_AZ_TZ2 }}
export VAULT_AZ_TZ3=${{ secrets.INTEGRATIONTEST_VAULT_AZ_TZ3 }}

export VAULT_GCP_PROJECTID=${{ secrets.INTEGRATIONTEST_VAULT_GCP_PROJECTID }}
export VAULT_GCP_PRIVATEKEYID=${{ secrets.INTEGRATIONTEST_VAULT_GCP_PRIVATEKEYID }}
export VAULT_GCP_PRIVATEKEY=${{ secrets.INTEGRATIONTEST_VAULT_GCP_PRIVATEKEY }}
Expand Down
21 changes: 16 additions & 5 deletions integration_test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ The tests in this folder use a docker compose file to orchestrate the starting o

The version of Signatory that is run is defined by an environment variable named `IMAGE`.

The `octez-client` that is run by the tests is provided by the `tezos` container, not the `octez-client` that is onboard the `flextesa` image, so that official `tezos` image releases can be used. The version of `tezos` container is defined by an environment variable named `OCTEZ_VERSION`.
The `octez-client` that is run by the tests is provided by the `tezos` container. The version of `tezos` container is defined by an environment variable named `OCTEZ_VERSION`.

Currently, it is always the `latest` version of the `flextesa` image that is run by the tests. The economic protocol run by flextesa is defined by an environment variable named `PROTOCOL`

Expand Down Expand Up @@ -76,17 +76,20 @@ Github secrets are used to define vault env var used in github workflows. To run
. .env.vaults
```

<<<<<<< HEAD
### optional: using GCP vault
### using GCP vault

If you want to run GCP vault tests you need to substitute GCP vault env var into the GCP token file that gets mounted to Signatory file system:

```sh
envsubst < gcp-token-template.json > gcp-token.json
```

=======
>>>>>>> main
### using AZ vault

```sh
echo $VAULT_AZ_SP_KEY |base64 -d >service-principal.key
```

Next, start the stack:

```sh
Expand Down Expand Up @@ -124,3 +127,11 @@ Most tests can be re-run successfully as detailed above. Some tests (like the `
## Notes to the operator

Some tests in this folder make edits to `signatory.yaml` configuration and restart the Signatory service. By design, tests that do this shall clean up after themselves by restoring the copy of the file that is in the code repository. If `git status` after a test run shows you have modifications to the `signatory.yaml` file, then that would mean a test is failing to clean up after itself and should be corrected. Function `backup_then_update_config()` and `defer restore_config()` should be used by tests that edit config. Likewise, `git status` may show you new files in the `.tezos-client` folder, another indication of a test not cleaning up after itself. Function `clean_tezos_folder()` should be used by tests that leave state behind in `.tezos-client`.

The PEM file that is used for AZ authentication is stored in env var `VAULT_AZ_SP_KEY` which in github actions is supplied via secret `${{ secrets.INTEGRATIONTEST_VAULT_AZ_SP_KEY }}`. Because github secrets do not support multiline values, the PEM file content was base64 encoded before entered as the value of the secret. With the private key in a file named `service-principal.key` the base64 value is generated by:

```sh
cat service-principal.key|base64 -e >service-principal.base64
```

The string value in file `service-principal.base64` is then used in env var `VAULT_AZ_SP_KEY`.
4 changes: 4 additions & 0 deletions integration_test/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ services:
target: /etc/secret.json
- source: gcp-token
target: /etc/gcp-token.json
- source: az-sp-key
target: /etc/service-principal.key
environment:
- GOOGLE_APPLICATION_CREDENTIALS=/etc/gcp-token.json
command: serve
Expand All @@ -96,3 +98,5 @@ configs:
file: ./signatory-local-secret.json
gcp-token:
file: ./gcp-token.json
az-sp-key:
file: ./service-principal.key
4 changes: 3 additions & 1 deletion integration_test/service.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package integrationtest

import (
"fmt"
"os/exec"
)

Expand All @@ -9,8 +10,9 @@ func restart_signatory() {
if err != nil {
panic("failed to stop signatory")
}
_, err = exec.Command("docker", "compose", "-f", "./docker-compose.yml", "up", "-d", "--wait", "signatory").CombinedOutput()
out, err := exec.Command("docker", "compose", "-f", "./docker-compose.yml", "up", "-d", "--wait", "signatory").CombinedOutput()
if err != nil {
fmt.Println("restart signatory: failed to start: " + string(out))
panic("failed to start signatory during restart")
}
}
Expand Down
70 changes: 70 additions & 0 deletions integration_test/vault_az_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package integrationtest

import (
"os"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestAZVault(t *testing.T) {

spkey := "/etc/service-principal.key"

thumb := os.Getenv("VAULT_AZ_CLIENTCERTTHUMB")
clientid := os.Getenv("VAULT_AZ_CLIENTID")
resgroup := os.Getenv("VAULT_AZ_RESGROUP")
subid := os.Getenv("VAULT_AZ_SUBID")
tenantid := os.Getenv("VAULT_AZ_TENANTID")
vault := os.Getenv("VAULT_AZ_VAULT")

tz2 := os.Getenv("VAULT_AZ_TZ2")
tz3 := os.Getenv("VAULT_AZ_TZ3")

tz2alias := "aztz2"
tz3alias := "aztz3"

//config
var c Config
c.Read()
var v VaultConfig
v.Driver = "azure"
v.Conf = map[string]*string{"vault": &vault, "tenant_id": &tenantid, "client_id": &clientid, "client_private_key": &spkey, "client_certificate_thumbprint": &thumb, "subscription_id": &subid, "resource_group": &resgroup}
c.Vaults["azure"] = &v
var p TezosPolicy
p.LogPayloads = true
p.Allow = map[string][]string{"generic": {"reveal", "transaction"}}
c.Tezos[tz2] = &p
c.Tezos[tz3] = &p
backup_then_update_config(c)
defer restore_config()
restart_signatory()

//setup
out, err := OctezClient("import", "secret", "key", tz2alias, "http://signatory:6732/"+tz2)
assert.NoError(t, err)
assert.Contains(t, string(out), "Tezos address added: "+tz2)
defer OctezClient("forget", "address", tz2alias, "--force")
out, err = OctezClient("import", "secret", "key", tz3alias, "http://signatory:6732/"+tz3)
assert.NoError(t, err)
assert.Contains(t, string(out), "Tezos address added: "+tz3)
defer OctezClient("forget", "address", tz3alias, "--force")

out, err = OctezClient("transfer", "100", "from", "alice", "to", tz2alias, "--burn-cap", "0.06425")
assert.NoError(t, err)
require.Contains(t, string(out), "Operation successfully injected in the node")
out, err = OctezClient("transfer", "100", "from", "alice", "to", tz3alias, "--burn-cap", "0.06425")
assert.NoError(t, err)
require.Contains(t, string(out), "Operation successfully injected in the node")

//test
/* the tz2 key produces invalid signature 50% of the time from octez-client perspective
out, err = OctezClient("transfer", "1", "from", tz2alias, "to", "alice", "--burn-cap", "0.06425")
assert.NoError(t, err)
require.Contains(t, string(out), "Operation successfully injected in the node")
*/
out, err = OctezClient("transfer", "1", "from", tz3alias, "to", "alice", "--burn-cap", "0.06425")
assert.NoError(t, err)
require.Contains(t, string(out), "Operation successfully injected in the node")
}