Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 9 additions & 0 deletions .mockery.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,12 @@ packages:
interfaces:
PolicyServiceClient:
LabelServiceClient:
buf.build/gen/go/safedep/api/grpc/go/safedep/services/controltower/v1/controltowerv1grpc:
config:
include-auto-generated: true
dir: "internal/cmd/workload/mocks"
pkgname: "mocks"
structname: "{{.InterfaceName}}Mock"
filename: "{{.InterfaceName}}_mock.go"
interfaces:
WorkloadAdminServiceClient:
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ to a project and why.
**Audit log**: `safedep audit`
See who changed the policy, what, and when.

**Workload identity**: `safedep workload`
Let GitHub Actions jobs call SafeDep Cloud with no API key. Create the trust rules
that say which repositories, refs and events get a credential, and see why a job
got none.

**Security telemetry queries**: `safedep query`
Run SQL against SafeDep Cloud's query service. Inspect packages, events, and findings
across your entire fleet.
Expand Down Expand Up @@ -153,6 +158,12 @@ Push SafeDep malware findings to external security tools. JFrog XRay is supporte
| [`safedep policy rule delete`](./docs/cmd/policy-rule-delete.md) | Delete a package rule |
| [`safedep policy decision list`](./docs/cmd/policy-decision-list.md) | List the decisions that the policy made, and where |
| [`safedep audit event list`](./docs/cmd/audit-event-list.md) | List audit events of the tenant |
| [`safedep workload provider list`](./docs/cmd/workload-provider-list.md) | List the workload identity providers of the tenant |
| [`safedep workload rule create`](./docs/cmd/workload-rule-create.md) | Create a workload trust rule |
| [`safedep workload rule list`](./docs/cmd/workload-rule-list.md) | List workload trust rules |
| [`safedep workload rule show`](./docs/cmd/workload-rule-show.md) | Show one workload trust rule |
| [`safedep workload rule delete`](./docs/cmd/workload-rule-delete.md) | Delete a workload trust rule |
| [`safedep workload exchange list`](./docs/cmd/workload-exchange-list.md) | List workload exchanges, newest first |
| [`safedep query exec`](./docs/cmd/query-exec.md) | Execute a SQL query against SafeDep Cloud |
| [`safedep query schema list`](./docs/cmd/query-schema-list.md) | List tables in the query schema |
| [`safedep query schema show`](./docs/cmd/query-schema-show.md) | Show one table from the query schema |
Expand Down
67 changes: 67 additions & 0 deletions docs/cmd/workload-exchange-list.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# safedep workload exchange list

List the workload exchanges of the tenant, newest first. Each exchange is one
request of a CI job for a credential: SafeDep issued it or denied it. The server
keeps an exchange for 30 days.

## Synopsis

```
safedep workload exchange list [--denied] [--since DURATION] [--rule RULE]
[--limit N] [--page-token TOKEN] [--output table|plain|json]
```

## Flags

| Flag | Description |
|------|-------------|
| `--denied` | Only the exchanges that the server denied. |
| `--since <duration>` | Only exchanges in this time before now, as `7d` or `12h`. |
| `--rule <rule>` | Only exchanges that this rule matched: a rule id, or the name of a live rule. The id of a deleted rule also works. |
| `--limit <n>` | Page size. The server default applies when 0. |
| `--page-token <token>` | Continuation token from a prior response. |

## Examples

A CI job got no credential. Find out why:

```bash
safedep workload exchange list --denied --since 1d
```

```
Workload exchanges
WHEN OUTCOME WORKLOAD RULE DETAIL
5m ago denied github:acme/web@refs/heads/feature-x run 987/1 - no workload trust rule gives TOOL to acme/web on refs/heads/feature-x
1 exchange
```

The reason names the missing rule. Create a rule that covers the job with
[`safedep workload rule create`](./workload-rule-create.md). For an issued
exchange, `DETAIL` says when the credential expires, or when it was revoked.

When `--rule` names no live rule, the CLI sends the value as a rule id. If no
exchange matches, the command says that no live rule has that name or id. To list
the exchanges of a deleted rule, pass its rule id.

## Output

`json` holds `exchanges` (exchange id, outcome, denial reason, rule id, provider
id, grant, display identity, the kept claims, endpoint id, and the times of the
exchange, the expiry and the revocation) and `next_page_token`. `plain` writes a
tab-separated header and one row for each exchange.

## Permissions

Needs the Admin role.

## Authentication

Requires a control-plane OAuth session. Run `safedep auth login` first.

## Exit codes

| Code | Meaning |
|------|---------|
| `0` | The page was read. |
| non-zero | Validation or the request failed. |
60 changes: 60 additions & 0 deletions docs/cmd/workload-provider-list.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# safedep workload provider list

List the workload identity providers of the tenant. A provider trusts the
identity tokens of one platform account, such as the GitHub Actions tokens of
the GitHub organization `acme`. A verified link of the SafeDep GitHub App
creates the provider of its account. No command creates a provider.

## Synopsis

```
safedep workload provider list [--limit N] [--page-token TOKEN] [--output table|plain|json]
```

## Flags

| Flag | Description |
|------|-------------|
| `--limit <n>` | Page size. The server default applies when 0. |
| `--page-token <token>` | Continuation token from a prior response. |

## Examples

```bash
safedep workload provider list
```

```
Workload identity providers
PROVIDER ID OWNER ID LINK CREATED
github-actions:acme wip_7a1 1001 active 2d ago
1 provider
```

`PROVIDER` is the `KIND:ACCOUNT` name that
[`safedep workload rule create --provider`](./workload-rule-create.md) takes.
`OWNER ID` is the immutable id of the account. A rule matches this id, never the
account name. A CI job gets a credential only through a provider whose `LINK` is
`active`. `suspended` means that GitHub suspended the installation of the
SafeDep GitHub App. `unlinked` means that the link is gone.

## Output

`json` holds `providers` (provider id, name, kind, account login, owner id, link
state, link id, creation time) and `next_page_token`. `plain` writes a
tab-separated header and one row for each provider.

## Permissions

Needs the Admin role.

## Authentication

Requires a control-plane OAuth session. Run `safedep auth login` first.

## Exit codes

| Code | Meaning |
|------|---------|
| `0` | The page was read. |
| non-zero | Authentication or the request failed. |
126 changes: 126 additions & 0 deletions docs/cmd/workload-rule-create.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# safedep workload rule create

Create a workload trust rule. The rule gives one credential grant to the CI jobs
of one provider whose claims meet every condition of the rule. A job of a GitHub
Actions workflow then calls SafeDep with no API key in the CI secrets.

## Synopsis

```
safedep workload rule create NAME --provider PROVIDER --grant GRANT
[--repository OWNER/NAME...] [--ref REF...] [--event EVENT...]
[--project-binding auto|manual] [--max-lifetime DURATION]
[--output table|plain|json]
```

`NAME` is unique in the tenant: 1 to 63 lowercase letters, digits and hyphens,
as in `org` or `web-release`.

## Flags

| Flag | Description |
|------|-------------|
| `--provider <provider>` | The provider of the rule: a provider id or `KIND:ACCOUNT`, as in `github-actions:acme`. Required. |
| `--grant <grant>` | The grant that the rule gives. `tool` lets the job call the RPCs that pmg, vet and the `safedep` CLI use. Required. |
| `--repository <owner/name>` | A repository by its full name, as in `acme/web`. Repeat the flag, or separate names with commas. At most 100 repositories. |
| `--ref <ref>` | A full ref, as in `refs/heads/main`, or a prefix that ends with `/*`, as in `refs/heads/release/*`. Repeat the flag for more refs. |
| `--event <event>` | An event name of the platform, as in `push` or `pull_request_target`. Repeat the flag for more events. |
| `--project-binding <binding>` | How a repository with no project gets a project: `auto` or `manual`. See [Projects](#projects). |
| `--max-lifetime <duration>` | The longest life of a credential that the rule gives, from `1m` to `6h`, as in `30m`. The server default is `6h`. |

## The provider is required

The CLI never picks a provider, even when the tenant has one provider. With no
`--provider`, the command fails and lists the providers of the tenant:

```
--provider is required. The CLI never picks a provider. The providers of the tenant:
github-actions:acme id wip_7a1, link active
Run the command again with --provider github-actions:acme
```

## Repositories

The server finds each `--repository` in the account of the provider, through the
installation of the SafeDep GitHub App, and stores its numeric id. The rule
matches the id, so a rename of the repository does not change the rule. The
server refuses a repository that the installation cannot see:

```
the GitHub installation of the provider cannot see a repository
other/web is not a repository of the provider account that the installation can see
```

A rule with no `--repository` covers every repository of the account, also the
repositories that the installation does not select. The command says so when
it creates such a rule.

## Conditions

- `--ref` takes full refs or prefixes, not both. A prefix ends at a `/`, so
`refs/heads/main*` is refused: it would also match `refs/heads/main-evil`.
- A rule with no `--event` covers only the default events of the provider. For
GitHub Actions they are `push`, `pull_request`, `merge_group`, `schedule`,
`workflow_dispatch` and `release`. Any other event, such as `issues` or
`pull_request_target`, matches only a rule that lists it with `--event`.

## Projects

`--project-binding` says how a repository with no project gets a project:

- `auto`: the first tool session of the repository creates its project.
- `manual`: a member adds the repository as a project first. A tool session
from a repository with no project fails. Policy fetch and event sync still work.

With no `--project-binding`, the server picks: `auto` for a rule with no
repository, and `manual` for a rule with repositories.

## Examples

One rule for every repository of the organization:

```bash
safedep workload rule create org --provider github-actions:acme --grant tool
```

One rule for the release branches of one repository:

```bash
safedep workload rule create web-release --provider github-actions:acme --grant tool \
--repository acme/web --ref 'refs/heads/release/*'
```

```
✓ rule web-release created
Rule wtr_9d1
Name web-release
Provider github-actions:acme
Grant tool
Repositories acme/web (123456)
Conditions ref matches refs/heads/release/*
Projects manual: a repository with no project needs a project before a tool session
Max lifetime 6h
Created now
Last used never
```

## Output

The command prints the rule as [`safedep workload rule show`](./workload-rule-show.md)
does. `json` holds `rule`, with each repository as `repository_id` and
`full_name`, and `every_repository`.

## Permissions

Needs the Admin role. The server records an audit event.

## Authentication

Requires a control-plane OAuth session. Run `safedep auth login` first.

## Exit codes

| Code | Meaning |
|------|---------|
| `0` | The rule was created. |
| non-zero | Validation failed, the provider is missing or unknown, the server refused a repository, or the request failed. |
60 changes: 60 additions & 0 deletions docs/cmd/workload-rule-delete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# safedep workload rule delete

Delete a workload trust rule by its id or its name. Every workload credential
that the rule gave stops working within 30 seconds, and the CI jobs that the
rule admits lose access to SafeDep Cloud.

## Synopsis

```
safedep workload rule delete RULE [--yes]
```

## Flags

| Flag | Description |
|------|-------------|
| `-y`, `--yes` | Delete the rule with no prompt. |

## Examples

```bash
safedep workload rule delete web
```

The command asks first. With no terminal, pass `--yes`.

```
The CI jobs that rule web admits, in acme/web, lose access to SafeDep Cloud. Delete it? [y/N]:
```

For a rule with no repository, the question says that the rule covers every
repository of the account:

```
Rule org covers every repository of acme. The CI jobs of every repository that it admits lose access to SafeDep Cloud. Delete it? [y/N]:
```

```
✓ rule wtr_9d1 deleted
Every workload credential that the rule gave stops working within 30 seconds
```

The exchanges of the rule stay in
[`safedep workload exchange list --rule`](./workload-exchange-list.md), by the
rule id.

## Permissions

Needs the Admin role. The server records an audit event.

## Authentication

Requires a control-plane OAuth session. Run `safedep auth login` first.

## Exit codes

| Code | Meaning |
|------|---------|
| `0` | The rule was deleted, or you answered no and nothing was deleted. |
| non-zero | The rule does not exist, or the request failed. |
Loading
Loading