Feynman Zhou
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Sign and verify an artifact with HashiCorp Vault KMS >**Note** Certificate in this guide is generated using OpenSSL for development and testing purposes. You need to use a certificate registered from a trusted CA in production. ## Outline - Install and Configure Vault Development Server - Generate Key and Certificate and Import them to Vault - Add the Key to Notation and Sign the Artifact ## Install Notation-HC-Vault plugin and key import utility 1. Download this repo ```bash git clone https://github.com/OliverShang/notation-hc-vault.git ``` 2. Build the plugin ```bash cd notation-hc-vault/cmd/notation-hc-vault go build . ``` 3. Install the plugin to the notation path specified by [notation plugin spec](https://github.com/notaryproject/notaryproject/blob/main/specs/plugin-extensibility.md#installation). The folder structure should be like `$XDG_CONFIG_HOME/notation/plugins/hc-vault/notation-hc-vault` 4. Build the key import utility ```bash cd notation-hc-vault/key-helper go build . ``` ## Install and Configure Vault Server 1. [Install Hashi Corp Vault](https://developer.hashicorp.com/vault/downloads) 2. Start the Vault development server or production server 2.1 Start Vault development server (skip to step 2.2 if you want to use the production server) ```bash vault server -dev ``` - In your browser, open `127.0.0.1:8200` to see the webpage of your vault server. 2.2 Start Vault production server (skip to step 3 if you are using the dev server) - Create a vault config file udner your work directory. A minimal working example is shown below, more details about config can be found [here](https://developer.hashicorp.com/vault/tutorials/operations/configure-vault#configuration-files)): ```bash disable_mlock = true ui = true listener "tcp" { address = "127.0.0.1:8200" tls_disable = "true" } storage "file" { path = "/tmp/vault-data" } ``` - In your browser, open `127.0.0.1:8200` to see the webpage of your vault server. - Initiate vault on webpage Setup the root keys. In this example, the root key is split into 3 key shares, and any two keys of the three will be sufficient to unseal the Vault, [see details](https://developer.hashicorp.com/vault/docs/concepts/seal). ![](https://hackmd.io/_uploads/HJZnBfwV2.png) Be aware and distribute the keys/root token conscientiously. For testing purposes, just use the root token as `VAULT_TOKEN`. ![](https://hackmd.io/_uploads/ByNidMDNh.png) ! IMPORTANT !: Remember to hit the `Download Keys` button before going forward. Both keys and the initial root token are downloaded. They are used in the next step. - Unseal the Vault Enter two of the three keys generated previously to unseal the vault. ![](https://hackmd.io/_uploads/SyqhtGv4h.png) By now the Vault production server is ready for testing. 3. Set environment variables - Launch a new terminal session. - Copy and run the `export VAULT_ADDR ...` command from the terminal output. This will configure the Vault client to talk to your server (dev or prod). ```bash export VAULT_ADDR='http://127.0.0.1:8200' ``` Vault CLI determines which Vault servers to send requests using the `VAULT_ADDR` environment variable. - Set the `VAULT_TOKEN` environment variable value to the generated **Root Token** value displayed in the terminal output. ```bash export VAULT_TOKEN="hvs.**************" ``` 4. Enable Transit Secrets Engine and KV Secrets Engine ```bash vault secrets enable transit vault secrets enable -path=secret kv-v2 ``` ## Generate Key and Certificate and Import them to Vault 1. Generate CA root certificate ```bash openssl genrsa -out ca.key 2048 openssl req -new -x509 -days 365 -key ca.key -subj "/O=Notation/CN=Notation Root CA" -out ca.crt -addext "keyUsage=critical,keyCertSign" ``` 2. Generate private key and leaf certificate ```bash openssl genrsa -out leaf.key 2048 openssl req -newkey rsa:2048 -nodes -keyout leaf.key -subj "/CN=Notation.leaf" -out leaf.csr openssl x509 -req -extfile <(printf "basicConstraints=critical,CA:FALSE\nkeyUsage=critical,digitalSignature") -days 365 -in leaf.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out leaf.crt ``` 3. Combine the CA certificate and leaf certificate in a pem file (CA certificate after leaf certificate) ```bash cat leaf.crt ca.crt > certificate_chain.pem ``` 4. Import certificate and private key using the key import utility ```bash cd notation-hc-vault/key-helper key-helper import --cert_path "{path-to-cert}/combined_cert.pem" --key_name "openssl" --key_path "{path-to-key}/leaf.key" ``` ## Add the Key to Notation and Sign the Artifact 1. Add the key to Notation and associate it with hc-vault plugin ```bash notation key add "openssl-key" --id "openssl-key" --plugin "hc-vault" ``` 2. Sign the artifact ```bash notation sign --oci-layout "{path-to-artifact}/oci-layout:v2" --key openssl-key ``` You should expect an output similar to this: ```bash Warning: Always sign the artifact using digest(@sha256:...) rather than a tag(:v2) because tags are mutable and a tag reference can point to a different artifact than the one signed. Successfully signed C:\xxx\oci-layout@sha256:19dbd2e48e921426ee8ace4dc892edfb2ecdc1d1a72d5416c83670c30acecef0 ``` 3. List the signature ```bash notation list --oci-layout "{path-to-artifact}/oci-layout:v2" ``` You should expect an output similar to this: ```bash {path-to-artifact}\oci-layout@sha256:19dbd2e48e921426ee8ace4dc892edfb2ecdc1d1a72d5416c83670c30acecef0 └── application/vnd.cncf.notary.signature └── sha256:22a1636b458eecd06cda488099b301e89a155df2460e447ea9ce6d4fcc6d59da ``` 4. Add the CA certificate to the trust store ```bash notation cert add -t ca -s alpine "{path-to-ca-cert}/ca.crt" ``` 5. Verify the signature ```bash notation verify --oci-layout "{path-to-artifact}/oci-layout:v2" --scope local/oci-layout2 ``` For successful verification, you should expect an output similar to this: ```bash Warning: Always verify the artifact using digest(@sha256:...) rather than a tag(:v2) because resolved digest may not point to the same signed artifact, as tags are mutable. Successfully verified signature for C:\Users\creep\Desktop\oci-layout@sha256:19dbd2e48e921426ee8ace4dc892edfb2ecdc1d1a72d5416c83670c30acecef0 ```

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully