Skip to content

Commit

Permalink
Remove leading dollar from all bash fragments (#255)
Browse files Browse the repository at this point in the history
* Remove leading dollar from all bash fragments

* Make all commands in querying-kosli tutorial copyable
  • Loading branch information
JonJagger authored Jul 18, 2024
1 parent 6032d13 commit b426c81
Show file tree
Hide file tree
Showing 6 changed files with 143 additions and 82 deletions.
38 changes: 19 additions & 19 deletions docs.kosli.com/content/tutorials/attest_snyk.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,21 @@ To follow the steps in this tutorial, you need to:
* [Get a Kosli API token](/getting_started/service-accounts/).
* Set the `KOSLI_ORG` environment variable to your personal org name and `KOSLI_API_TOKEN` to your token:
```shell {.command}
$ export KOSLI_ORG=<your-personal-kosli-org-name>
$ export KOSLI_API_TOKEN=<your-api-token>
export KOSLI_ORG=<your-personal-kosli-org-name>
export KOSLI_API_TOKEN=<your-api-token>
```
* Clone the Kosli CLI git repo
```shell {.command}
$ git clone https://github.com/kosli-dev/cli.git
$ cd cli
git clone https://github.com/kosli-dev/cli.git
cd cli
```

## Creating a Flow and Trail

We will start by creating a flow in Kosli to contain Trails and Artifacts for this demo.

```shell {.command}
$ kosli create flow snyk-demo --use-empty-template
kosli create flow snyk-demo --use-empty-template
```

{{<hint info>}}
Expand All @@ -52,7 +52,7 @@ $ kosli create flow snyk-demo --use-empty-template
Then, we can start a trail to bind our snyk attestations to.

```shell {.command}
$ kosli begin trail test-1 --flow snyk-demo
kosli begin trail test-1 --flow snyk-demo
```

Now we can start running Snyk scans and attest them to this trail.
Expand All @@ -68,9 +68,9 @@ After each attestation in the sections below, you can navigate to:

You can run a snyk opens source scan and report it to Kosli as follows:
```shell {.command}
$ snyk test --sarif-file-output=os.json
snyk test --sarif-file-output=os.json

$ kosli attest snyk --flow snyk-demo --trail test-1 --name open-source-scan --scan-results os.json --commit HEAD
kosli attest snyk --flow snyk-demo --trail test-1 --name open-source-scan --scan-results os.json --commit HEAD
```

{{<hint info>}}
Expand All @@ -84,9 +84,9 @@ $ kosli attest snyk --flow snyk-demo --trail test-1 --name open-source-scan --sc

You can run a snyk code scan and report it to Kosli as follows:
```shell {.command}
$ snyk code test --sarif-file-output=code.json
snyk code test --sarif-file-output=code.json

$ kosli attest snyk --flow snyk-demo --trail test-1 --name code-scan --scan-results code.json --commit HEAD
kosli attest snyk --flow snyk-demo --trail test-1 --name code-scan --scan-results code.json --commit HEAD
```

## Snyk Container scan
Expand All @@ -96,10 +96,10 @@ $ kosli attest snyk --flow snyk-demo --trail test-1 --name code-scan --scan-resu
You can run a snyk container scan and report it to Kosli as follows:
```shell {.command}
# pull the cli docker image before scanning it
$ docker pull ghcr.io/kosli-dev/cli:v2.8.3
$ snyk container test ghcr.io/kosli-dev/cli:v2.8.3 --file=Dockerfile --sarif-file-output=container.json
docker pull ghcr.io/kosli-dev/cli:v2.8.3
snyk container test ghcr.io/kosli-dev/cli:v2.8.3 --file=Dockerfile --sarif-file-output=container.json

$ kosli attest snyk --flow snyk-demo --trail test-1 --name container-scan --scan-results container.json --commit HEAD
kosli attest snyk --flow snyk-demo --trail test-1 --name container-scan --scan-results container.json --commit HEAD
```

## Snyk IaC scan
Expand All @@ -108,14 +108,14 @@ $ kosli attest snyk --flow snyk-demo --trail test-1 --name container-scan --scan

We can run a snyk IaC scan on the K8S reporter Helm chart and report it to Kosli as follows:
```shell {.command}
$ helm template ./charts/k8s-reporter --output-dir helm \
--set kosliApiToken.secretName=secret \
--set reporterConfig.kosliEnvironmentName=foo \
--set reporterConfig.kosliOrg=bar
helm template ./charts/k8s-reporter --output-dir helm \
--set kosliApiToken.secretName=secret \
--set reporterConfig.kosliEnvironmentName=foo \
--set reporterConfig.kosliOrg=bar

$ snyk iac test helm --sarif-file-output=helm.json
snyk iac test helm --sarif-file-output=helm.json

$ kosli attest snyk --flow snyk-demo --trail test-1 --name helm-scan --scan-results helm.json --commit HEAD
kosli attest snyk --flow snyk-demo --trail test-1 --name helm-scan --scan-results helm.json --commit HEAD
```

You can refer to the [Snyk docs](https://docs.snyk.io/snyk-cli/scan-and-maintain-projects-using-the-cli/snyk-cli-for-iac/test-your-iac-files) for more information on supported IaC configuration formats and how you can run snyk scans on them.
Expand Down
6 changes: 3 additions & 3 deletions docs.kosli.com/content/tutorials/cli_and_http_proxy.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ The same steps apply for different HTTP proxies and machines, but commands will
1. Start Tinyproxy using docker:

```shell {.command}
$ cat <<EOF > tinyproxy.conf
cat <<EOF > tinyproxy.conf
User nobody
Group nobody
Port 8888
EOF

$ docker run -p 8888:8888 -v $(PWD)/tinyproxy.conf:/etc/tinyproxy/tinyproxy.conf:ro kalaksi/tinyproxy
docker run -p 8888:8888 -v $(PWD)/tinyproxy.conf:/etc/tinyproxy/tinyproxy.conf:ro kalaksi/tinyproxy
```


Expand All @@ -44,7 +44,7 @@ Now you have an HTTP proxy running at http://localhost:8888
To verify if the setup works, you can run this command to list environments of the public demo org `Cyber Dojo`:

```shell {.command}
$ kosli list envs --org cyber-dojo --http-proxy http://localhost:8888 --api-token <<your-token>>
kosli list envs --org cyber-dojo --http-proxy http://localhost:8888 --api-token <<your-token>>
```
Your request goes through the HTTP proxy and is then forwarded to Kosli. If successful, you should see a similar output to this:
Expand Down
117 changes: 89 additions & 28 deletions docs.kosli.com/content/tutorials/querying_kosli.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ You need to:

You can use `kosli search` command to find out if Kosli knows of any artifact that was build using that commit - both short and full shas are accepted:

```shell {.command}
kosli search 0f5c9e1
```

```
$ kosli search 0f5c9e1
Search result resolved to commit 0f5c9e19c4d4f948d19ce4c8495b2a44745cda96
Name: cyberdojo/web:0f5c9e1
Fingerprint: 62e1d2909cc59193b31bfd120276fcb8ba5e42dd6becd873218a41e4ce022505
Expand All @@ -51,8 +54,11 @@ The information returned by `kosli search` - like Flow, Fingerprint or History -

When you search in Kosli you often need to refer to a specific flow. If you don't remember all the flows' names it is easy to list them with `kosli list flows` command:

```shell {.command}
kosli list flows
```

```
$ kosli list flows
NAME DESCRIPTION VISIBILITY
creator UX for Group/Kata creation public
custom-start-points Custom exercises choices public
Expand All @@ -70,8 +76,11 @@ web UX for practicing TDD public

And if you want to check metadata of a specific flow (like description or template) use `kosli get flow`

```shell {.command}
kosli get flow creator
```

```
$ kosli get flow creator
Name: creator
Description: UX for Group/Kata creation
Visibility: public
Expand All @@ -83,8 +92,11 @@ Last Deployment At: Wed, 14 Sep 2022 10:51:43 CEST • one month ago

To find the information about artifacts reported to a specific flow in Kosli use `kosli list artifacts` command

```shell {.command}
kosli list artifacts --flow creator
```

```
$ kosli list artifacts --flow creator
COMMIT ARTIFACT STATE CREATED_AT
344430d Name: cyberdojo/creator:344430d COMPLIANT Wed, 14 Sep 2022 10:48:09 CEST
Fingerprint: 817a72(...)6b5a273399c693
Expand All @@ -103,18 +115,18 @@ The output of the command is shortened above, for readability purposes.
The amount of artifacts may be really long and by default you can see the last 15 artifacts - the first page of the result list. You can use `-n` flag to limit the amount of artifacts displayed per page, and `--page` to select which page of the result list you want to see.

E.g. to see last five artifacts you'd use:
```
$ kosli list artifacts --flow creator -n 5
```shell {.command}
kosli list artifacts --flow creator -n 5
```

And to see the next page:
```
$ kosli list artifacts --flow creator -n 5 --page 2
```shell {.command}
kosli list artifacts --flow creator -n 5 --page 2
```

You can also use the `--output` flag to change the format of the response. By default the response comes in a *table* format, but you can choose to switch to *json*:
```
$ kosli list artifacts --flow creator --output json
```shell {.command}
kosli list artifacts --flow creator --output json
```
## Get artifact

Expand All @@ -125,9 +137,12 @@ OR

Both are available in the output of `kosli list artifacts` command

```shell {.command}
# search for an artifact by its fingerprint
kosli get artifact creator@817a72609041c51cd2a3bbbcbeb048c687677986b5a273399c6938b5e6aa1ded
```

```
# search for artifact by its fingerprint
$ kosli get artifact creator@817a72609041c51cd2a3bbbcbeb048c687677986b5a273399c6938b5e6aa1ded
Name: cyberdojo/creator:344430d
Flow: creator
Fingerprint: 817a72609041c51cd2a3bbbcbeb048c687677986b5a273399c6938b5e6aa1ded
Expand Down Expand Up @@ -156,9 +171,14 @@ History:
Started running in aws-beta#265 environment Wed, 19 Oct 2022 09:46:42 CEST
No longer running in aws-prod#257 environment Fri, 21 Oct 2022 11:02:28 CEST
Started running in aws-prod#259 environment Fri, 21 Oct 2022 11:05:28 CEST
```

```shell {.command}
# search for an artifact by its commit sha
kosli get artifact creator:344430d
```

# search for artifact by its commit sha
$ kosli get artifact creator:344430d
```
Name: cyberdojo/creator:344430d
Flow: creator
Fingerprint: 817a72609041c51cd2a3bbbcbeb048c687677986b5a273399c6938b5e6aa1ded
Expand Down Expand Up @@ -193,8 +213,11 @@ History:

As is the case for flows and artifacts, you can list all the Kosli environments you created under your organization

```shell {.command}
kosli list environments
```

```
$ kosli list environments
NAME TYPE LAST REPORT LAST MODIFIED
aws-beta ECS 2022-10-30T14:51:42+01:00 2022-10-30T14:51:42+01:00
aws-prod ECS 2022-10-30T14:51:28+01:00 2022-10-30T14:51:28+01:00
Expand All @@ -204,8 +227,11 @@ prod K8S 2022-06-15T11:40:01+02:00 2022-06-15T11:40:01+02:00

And get the metadata (including the type) of each environment:

```shell {.command}
kosli get environment aws-beta
```

```
$ kosli get environment aws-beta
Name: aws-beta
Type: ECS
Description: The ECS beta namespace
Expand All @@ -217,8 +243,11 @@ Last Reported At: Sun, 30 Oct 2022 14:55:42 CET • 5 seconds ago

When you have the name of the environment you want to dig into use `kosli list snapshots` or `kosli log environment` to browse snapshots and changes in the environment, or `kosli get snapshot` to have a look at a specific snapshot.

```shell {.command}
kosli list snapshots aws-beta
```

```
$ kosli list snapshots aws-beta
SNAPSHOT FROM TO DURATION
266 Wed, 19 Oct 2022 09:47:42 CEST now 11 days
265 Wed, 19 Oct 2022 09:46:42 CEST Wed, 19 Oct 2022 09:47:42 CEST 59 seconds
Expand All @@ -237,12 +266,15 @@ SNAPSHOT FROM TO DURATI
252 Mon, 10 Oct 2022 08:47:42 CEST Thu, 13 Oct 2022 09:04:42 CEST 3 days
```

By default you can see the last 15 changes to the environment. You can choose to only print e.g. last 3 events (`-n` flag).
By default, you can see the last 15 changes to the environment. You can choose to only print e.g. last 3 events (`-n` flag).

You can also choose to see the actual events from each snapshot, using `kosli log environment` command:

```shell {.command}
kosli log environment aws-beta
```

```
$ kosli log environment aws-beta
SNAPSHOT EVENT FLOW DEPLOYMENTS
#266 Artifact: 244531986313.dkr.ecr.eu-central-1.amazonaws.com/dashboard:d90a3e4 dashboard #15
Fingerprint: dd5308fdcda117c1ff3963e192a069ae390c2fe9e10e8abfa2430224265efe98
Expand All @@ -260,16 +292,26 @@ SNAPSHOT EVENT
Reported at: Wed, 19 Oct 2022 09:46:42 CEST
```

You can also use an *interval* expression, like `262..264` (to see specified snapshot list) , or `~4..NOW` (to get a list of snapshots starting from 4 behind a currently running one and the current one)
You can also use an *interval* expression, like `262..264` (to see specified snapshot list)

```shell {.command}
kosli log environment aws-beta 262..264
```

```
$ kosli log environment aws-beta 262..264
SNAPSHOT FROM TO DURATION
264 Wed, 19 Oct 2022 09:45:42 CEST Wed, 19 Oct 2022 09:46:42 CEST about a minute
263 Wed, 19 Oct 2022 09:42:42 CEST Wed, 19 Oct 2022 09:45:42 CEST 3 minutes
262 Wed, 19 Oct 2022 09:32:42 CEST Wed, 19 Oct 2022 09:42:42 CEST 10 minutes
```

or `~4..NOW` (to get a list of snapshots starting from 4 behind a currently running one and the current one)

```shell {.command}
kosli log environment aws-beta ~4..NOW
```

$ kosli log environment aws-beta ~4..NOW
```
SNAPSHOT FROM TO DURATION
266 Wed, 19 Oct 2022 09:47:42 CEST now 11 days
265 Wed, 19 Oct 2022 09:46:42 CEST Wed, 19 Oct 2022 09:47:42 CEST 59 seconds
Expand All @@ -282,8 +324,11 @@ SNAPSHOT FROM TO DURATI

To have a look at what is or was running in a given snapshot use `kosli get snapshot` command. You can use just the environment name as the argument, which will give you the latest snapshot, add `#` and snapshot number, to get a specific one, or `~n` where *n* is a number, to get *n-th* snapshot behind a current one:

```
$ kosli get snapshot aws-beta
``` shell {.command}
kosli get snapshot aws-beta
```

```
COMMIT ARTIFACT FLOW RUNNING_SINCE REPLICAS
d90a3e4 Name: 244531986313.dkr.ecr.eu-central-1.amazonaws.com/dashboard:d90a3e4 N/A 11 days ago 1
Fingerprint: dd5308fdcda117c1ff3963e192a069ae390c2fe9e10e8abfa2430224265efe98
Expand All @@ -294,8 +339,13 @@ d90a3e4 Name: 244531986313.dkr.ecr.eu-central-1.amazonaws.com/dashboard:d90a3e4
1c162e4 Name: 244531986313.dkr.ecr.eu-central-1.amazonaws.com/differ:1c162e4 N/A 11 days ago 1
Fingerprint: b7fd766dd2514b2610c0c8d70d8f762de4921931f97fdd6fbbfcc9745ac3ce3b
[...]
```

$ kosli get snapshot aws-beta#256
```shell {.command}
kosli get snapshot aws-beta#256
```

```
COMMIT ARTIFACT FLOW RUNNING_SINCE REPLICAS
6fe0d30 Name: 244531986313.dkr.ecr.eu-central-1.amazonaws.com/repler:6fe0d30 N/A 16 days ago 1
Fingerprint: a0c03099c832e4ce5f23f5e33dac9889c0b7ccd61297fffdaf1c67e7b99e6f8f
Expand All @@ -306,8 +356,13 @@ d90a3e4 Name: 244531986313.dkr.ecr.eu-central-1.amazonaws.com/dashboard:d90a3e4
1c162e4 Name: 244531986313.dkr.ecr.eu-central-1.amazonaws.com/differ:1c162e4 N/A 16 days ago 1
Fingerprint: b7fd766dd2514b2610c0c8d70d8f762de4921931f97fdd6fbbfcc9745ac3ce3b
[...]
```

```shell {.command}
kosli get snapshot aws-beta~19
```

$ kosli get snapshot aws-beta~19
```
COMMIT ARTIFACT FLOW RUNNING_SINCE REPLICAS
2e8646c Name: 244531986313.dkr.ecr.eu-central-1.amazonaws.com/shas:2e8646c N/A one month ago 1
Fingerprint: a3158c3e79c83905fd3613e06b8cf5a45141c50cf49d4f99de90a2d081b77771
Expand All @@ -324,8 +379,11 @@ The same expressions (with `#` and `~`) can be used to reference snapshots when

In the example below there was only one difference between snapshots: one new artifact started running in the latest snapshot.

```shell {.command}
kosli diff snapshots aws-beta aws-beta~1
```

```
$ kosli diff snapshots aws-beta aws-beta~1
Only present in aws-beta (snapshot: aws-beta#266)
Name: 244531986313.dkr.ecr.eu-central-1.amazonaws.com/dashboard:d90a3e4
Expand All @@ -339,8 +397,11 @@ Only present in aws-beta (snapshot: aws-beta#266)

You can use `diff` to compare snapshots of two different environments or different snapshots of the same environment:

```shell {.command}
kosli diff snapshots aws-beta~3 aws-prod
```

```
$ kosli diff snapshots aws-beta~3 aws-prod
Only present in aws-prod (snapshot: aws-prod#261)
Name: 274425519734.dkr.ecr.eu-central-1.amazonaws.com/saver:8d724a1
Expand Down
Loading

0 comments on commit b426c81

Please sign in to comment.