

# Getting started with Continuum for software supply chain

**Note**  
AWS Continuum for software supply chain is in preview release and is subject to change.

In this tutorial, you protect an npm install with AWS Continuum for software supply chain. You run the same install three times and watch the decision change: first with no policy, then with a policy rule in audit mode, then with the rule in enforce mode. You install packages with the Continuum for software supply chain CLI, and you manage the policy and review decisions with the AWS Command Line Interface (AWS CLI). The example package is `lodash` version 4.17.21. In each AWS CLI command, replace {{region}} with an AWS Region where Continuum for software supply chain is available, such as `us-east-1`.

For the terms used in this tutorial, such as policies, rules, enforcement modes, and package decisions, see [AWS Continuum for software supply chain concepts](sc-concepts.md).

## Prerequisites
<a name="sc-getting-started-prerequisites"></a>

Before you start, make sure that you have the following:
+ An AWS account.
+ IAM permissions for the actions that this tutorial uses. The Continuum for software supply chain CLI needs `continuum:CreatePackageDecision`. The policy and decision steps need `continuum:CreateSupplyChainPolicy`, `continuum:UpdateSupplyChainPolicy`, `continuum:DeleteSupplyChainPolicy`, `continuum:ListPackageDecisions`, and `continuum:GetPackageDecision`. For more information, see [Identity and access management for AWS Continuum](security-iam.md).
+ The AWS CLI, installed and configured with credentials for the account and an AWS Region where Continuum for software supply chain is available. For the Regions, see [Regions and endpoints](software-supply-chain.md#software-supply-chain-regions-endpoints).
+ npm, on the machine where you run the install. For the other package managers that the Continuum for software supply chain CLI supports, see [Run a package manager through the CLI](sc-cli.md#sc-cli-run).

## Step 1: Install the Continuum for software supply chain CLI
<a name="sc-getting-started-install"></a>

The Continuum for software supply chain CLI runs a package manager for you and requests a package decision for each package as the package manager downloads it. You put the `cscf` command before a package manager command, as in `cscf npm install {{package}}`. For what the CLI checks, see [Protecting package installs with the Continuum for software supply chain CLI](sc-cli.md).

Install the CLI from npm or from PyPI. Use one of the following commands.

To install from npm:

```bash
PROMPT> npm install --global @aws-continuum/continuum-supply-chain-firewall
```

To install from PyPI:

```bash
PROMPT> pip install aws-continuum-supply-chain-firewall
```

To check the install, print the CLI's version:

```bash
PROMPT> cscf --version
```

The CLI uses the same AWS credentials as the AWS CLI. For more information, see [Credentials](sc-cli-security.md#sc-cli-security-credentials).

## Step 2: Install a package that no rule matches
<a name="sc-getting-started-allow"></a>

Run the install through the Continuum for software supply chain CLI:

```bash
PROMPT> cscf npm install lodash@4.17.21
```

No rule matches the package yet, and the package isn't malicious, so Continuum for software supply chain allows it. The package manager installs the package, and the CLI returns with exit code `0`. For every exit code, see [Exit codes and fail-open behavior](sc-cli.md#sc-cli-exit-codes).

## Step 3: Create a policy in audit mode
<a name="sc-getting-started-audit"></a>

Create a policy with one rule that matches `lodash` version 4.17.21. Start the rule in audit mode, so Continuum for software supply chain records what it would deny without blocking anything.

1. Save the following policy as `audit-policy.json`:

   ```json
   {
     "name": "block-lodash",
     "description": "Block lodash 4.17.21 while we evaluate it",
     "rules": [
       {
         "ruleId": "deny-lodash",
         "enforcementMode": "AUDIT",
         "denyWhen": {
           "allOf": [
             {
               "signal": "PACKAGE_IDENTITY",
               "operator": "MATCHES",
               "value": {
                 "packageIdentity": {
                   "ecosystem": "npm",
                   "name": "lodash",
                   "version": "4.17.21"
                 }
               }
             }
           ]
         }
       }
     ]
   }
   ```

1. Create the policy, and note the policy ID in the output for the next steps:

   ```bash
   PROMPT> aws continuum create-supply-chain-policy \
       --region {{region}} \
       --policy file://audit-policy.json
   {
     "id": "{{policy-id}}",
     "arn": "{{policy-arn}}",
     "policy": {
       "name": "block-lodash",
       ...
     },
     "createdAt": "{{timestamp}}",
     "updatedAt": "{{timestamp}}"
   }
   ```
**Note**  
If you receive errors when you run AWS CLI commands, see [Troubleshooting errors for the AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-troubleshooting.html) in the *AWS CLI User Guide*. Also, make sure that you're using the most recent AWS CLI version.

1. Remove the package and clear npm's cache, so that the next install downloads the package again. The Continuum for software supply chain CLI checks only the packages that the package manager downloads:

   ```bash
   PROMPT> npm uninstall lodash
   PROMPT> npm cache clean --force
   ```

1. Run the install again. The rule matches the package, but it runs in audit mode, so the install still runs and the CLI returns with exit code `0`. At the end of the run, the CLI reports that the package would be denied by policy:

   ```bash
   PROMPT> cscf npm install lodash@4.17.21
   ...
   cscf: ⚠ 1 package(s) would be blocked once policy is enforced (audit mode):
       • pkg:npm/lodash@4.17.21 — would be denied by policy: POLICY_RULE_MATCHED (decision {{decision-id}})
   ```

**Note**  
You can create one customer managed policy for each account in each AWS Region. For more information, see [AWS Continuum quotas](quotas.md).

## Step 4: Switch the rule to enforce mode
<a name="sc-getting-started-enforce"></a>

When you're confident that a rule denies only what you expect, switch it to enforce mode.

1. Save a copy of the policy as `enforce-policy.json`, with the rule's `enforcementMode` changed to `ENFORCE`. Keep the policy's `name` and every rule ID the same: an update must use the existing name and include every existing rule.

1. Update the policy, using the policy ID from step 3:

   ```bash
   PROMPT> aws continuum update-supply-chain-policy \
       --region {{region}} \
       --id {{policy-id}} \
       --policy file://enforce-policy.json
   ```

1. Remove the package and clear npm's cache, so that the next install downloads the package again. The Continuum for software supply chain CLI checks only the packages that the package manager downloads:

   ```bash
   PROMPT> npm uninstall lodash
   PROMPT> npm cache clean --force
   ```

1. Run the install one more time. The rule now runs in enforce mode, so Continuum for software supply chain denies the package. The CLI blocks the install and returns with exit code `1`:

   ```bash
   PROMPT> cscf npm install lodash@4.17.21
   ...
   cscf: ⛔ blocked 1 package(s):
       • pkg:npm/lodash@4.17.21 — denied by the verdict service: POLICY_RULE_MATCHED (decision {{decision-id}})
   ```

   The decision ID in the output is the one that you pass to `get-package-decision` in step 5.

## Step 5: Review the decisions
<a name="sc-getting-started-review"></a>

Each install that you ran created a package decision. List your recent decisions. The output includes the audit decision from step 3 and the deny decision from step 4:

```bash
PROMPT> aws continuum list-package-decisions --region {{region}}
{
  "decisions": [
    {
      "decisionId": "{{decision-id}}",
      "evaluatedAt": "{{timestamp}}",
      "completedAt": "{{timestamp}}",
      "canonicalPurl": "pkg:npm/lodash@4.17.21",
      "evaluatedAction": "DENY",
      "enforcementAction": "DENY",
      "enforcementMode": "ENFORCE",
      "reason": "POLICY_RULE_MATCHED"
    },
    {
      "decisionId": "{{decision-id}}",
      "evaluatedAt": "{{timestamp}}",
      "completedAt": "{{timestamp}}",
      "canonicalPurl": "pkg:npm/lodash@4.17.21",
      "evaluatedAction": "DENY",
      "enforcementAction": "ALLOW",
      "enforcementMode": "AUDIT",
      "reason": "POLICY_RULE_MATCHED"
    },
    ...
  ]
}
```

The decision from step 3 has an `evaluatedAction` of `DENY` but an `enforcementAction` of `ALLOW`, because its rule ran in audit mode. Your client acts on `enforcementAction`. For what each field and reason means, see [Decision fields and reasons](sc-concepts.md#sc-concepts-decisions-reasons).

To read one decision again, pass its ID:

```bash
PROMPT> aws continuum get-package-decision \
    --region {{region}} \
    --decision-id {{decision-id}}
```

To get a decision for a package without installing it, request one directly:

```bash
PROMPT> aws continuum create-package-decision \
    --region {{region}} \
    --purl pkg:npm/lodash@4.17.21
```

For decisions, their evidence, and how long Continuum for software supply chain keeps them, see [Reviewing package decisions and evidence](sc-decisions.md).

## Step 6: Clean up
<a name="sc-getting-started-clean-up"></a>

To remove the tutorial policy, delete it:

```bash
PROMPT> aws continuum delete-supply-chain-policy --region {{region}} --id {{policy-id}}
```

For more about policies, see [Managing supply chain policies](sc-policies.md).

## Next steps
<a name="sc-getting-started-next-steps"></a>

Now that you've seen allow, audit, and deny decisions, learn more about Continuum for software supply chain:
+ For an overview of Continuum for software supply chain and how a decision works, see [Software supply chain](software-supply-chain.md).
+ For the terms and the way Continuum for software supply chain evaluates a package, see [AWS Continuum for software supply chain concepts](sc-concepts.md).
+ For the permissions that control access to Continuum for software supply chain, see [Identity and access management for AWS Continuum](security-iam.md).
+ To run the Continuum for software supply chain CLI in a CI/CD pipeline and act on its exit codes, see [Protecting package installs with the Continuum for software supply chain CLI](sc-cli.md).
+ To let a specific package install despite a rule, see [Managing policy exceptions](sc-policy-exceptions.md).
+ If something doesn't work as you expect, see [Troubleshooting AWS Continuum for software supply chain](sc-troubleshooting.md).