Shiwei Zhang
    • 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
    # Notation Offline Signing ###### tags: `notary` ## Overview By default, the `notation` CLI signs an artifact by signing its manifest obtained from the remote registry. Moreover, the `notation` CLI is capable of offline signing as required by the [Notary V2 Requirement](https://github.com/notaryproject/notaryproject/blob/main/requirements.md#goals). To reduce ambiguity, **offline signing** is defined as signing artifacts without the access to the Internet and to any registries. *Offline signing* is also often called **local signing**. Additionally, offline signing is usually operated on a single host but it is not restricted to a cluster or a pipeline within a private network. ## Signing Local Content Following the the [signature specification](https://github.com/notaryproject/notaryproject/blob/main/signature-specification.md), the `notation` CLI allows signing arbitrary content by computing its descriptor. ### Signing To sign a file `manifest.json` of media type `application/vnd.oci.image.index.v1+json`, use the `--local` option to indicate local reference: ```shell notation sign --local --media-type application/vnd.oci.image.index.v1+json manifest.json ``` If the `--media-type` option does not present, the manifest is assumed to be a docker image manifest of media type `application/vnd.docker.distribution.manifest.v2+json`. Alternatively, a binary steam from standard input is accepted by passing `-` as the reference: ```shell notation sign --local \ --media-type application/vnd.oci.image.index.v1+json - < manifest.json ``` By default, the resulted signature is stored in the cache. It is possible to write the signature to any desired path by the `--output` option. For instance, write the signature to `manifest.sig`: ```shell notation sign --local --output manifest.sig \ --media-type application/vnd.oci.image.index.v1+json manifest.json ``` Signing with time stamping is still available in the offline signing with the `--timestamp` option. Since there is no Internet access, time stamping by *public* TSAs are not available. ### Verification Similar to the signing process, offline verification can be done using the `--local` option, the `--media-type` option, and the `--signature` option. For instance, verify the manifest file `manifest.json` of a target artifact of media type `application/vnd.oci.image.index.v1+json` against a given signature file `manifest.sig`: ```shell notation verify --local --signature manifest.sig \ --media-type application/vnd.oci.image.index.v1+json manifest.json ``` If the `--signature` option does not present, the `notation` CLI tries to read signatures from the cache. ## Manifest Source As mentioned in the above section, the `notation` CLI is able to sign any content, which implies that it is able to sign any artifact by signing its manifest. However, the `notation` CLI *does not know and should not know* how the manifest to be signed is generated. In other words, it is the responsibility of the artifact manufacturer to produce the manifest and then present to the `notation` CLI for signing. For example, suppose we have the following command, ```shell notation sign --local registry.wabbit-networks.io/net-monitor:v1 ``` the `notation` CLI has no idea about which local provider provides the manifest of the image `registry.wabbit-networks.io/net-monitor:v1`. It could be `dockerd`, `buildkit`, `containerd`, `oras`, or other artifact manufacturers. One may think about having provider registration in the `notation` CLI like ```shell notation sign --local dockerd://registry.wabbit-networks.io/net-monitor:v1 ``` However, it introduces unnecessary complexities that each artifact manufacturer has to - Implement `notation` specific artifact provider, - Register itself in the Notation configuration, - Be available alongside the `notation` CLI on the same host, - Not suitable for pipeline scenarios. - Offload image-specific options to a configuration file. Therefore, the following process is suggested for *offline signing*: - Stage 1: Produce a manifest with desired tools for the target artifact. - The manifest MUST be exactly the same as the one, which will be pushed to the remote registry. - Stage 2: Pass the manifest in the stage 1 to `notation sign --local`. It is worth noting that the stage 1 and the stage 2 can be processed on different hosts. Similarly, the following process is suggested for *offline verification*: - Stage 1: Produce a manifest with desired tools for the target artifact. - Stage 2: Pass the manifest in the stage 1 to `notation verify --local`. ### Docker Integration Docker does not store image manifests on the local disk. Instead, it generates manifests for the images when they are being pushed. To offline sign a docker image, we need to generate the image manifest in the way exactly the same as the `docker push` command. We can leverage the [docker generate](https://github.com/notaryproject/notation/tree/main/cmd/docker-generate) plugin to generate a docker manifest of media type `application/vnd.docker.distribution.manifest.v2+json` from a *local* docker image, ```shell docker generate manifest net-monitor:v1 > net-monitor_v1.json ``` In the pure offline scenarios, docker images are transferred via tarballs. The `docker generate` plugin is also capable of generating manifests for images in tar archives: ```bash # Save the `net-monitor:v1` image to a tarball `net-monitor_v1.tar` # and transfer it to other hosts via offline physical means. docker save -o net-monitor_v1.tar net-monitor:v1 # On the other host, generate the manifest from the received tarball. docker generate manifest < net-monitor_1.tar > net-monitor_v1.json ``` Once we have the manifest file of the docker image, we can do `notation sign` and `notation verify` for offline signing and verification. ### Containerd Integration `containerd` stores image manifests on the local disk in its content store located at ``` /var/lib/containerd/io.containerd.content.v1.content/blobs/<algorithm>/<hash> ``` To offline sign an image, we need find out the manifest of the image and its media type. The following bash script `get_manifest.sh` finds out the manifest of a target image and its media type, using the `ctr` tool. The media type will be written to the standard output, and the manifest will be copied to `manifest.json` in the working folder. ```bash #!/bin/bash name=$1 sudo ctr images check name==$name | ( read column_names read ref type digest others if [[ -z $ref ]]; then echo "$name: not found" exit 1 fi echo $type path="/var/lib/containerd/io.containerd.content.v1.content/blobs/${digest/:/\/}" cp --no-preserve=mode $path manifest.json ) ``` For instance, offline signs the `registry.wabbit-networks.io/net-monitor:v1` and save the signature in the cache, ```bash media_type=$(./get_manifest.sh registry.wabbit-networks.io/net-monitor:v1) notation sign --local --media-type $media_type manifest.json ``` For advanced users, the above two scripts can be combined as a single script `sign.sh` so that no intermediate file is generated. ```bash #!/bin/bash name=$1 sudo ctr images check name==$name | ( read column_names read ref type digest others if [[ -z $ref ]]; then echo "$name: not found" exit 1 fi path="/var/lib/containerd/io.containerd.content.v1.content/blobs/${digest/:/\/}" notation sign --local --media-type $type $path ) ``` Similarly, offline verification can be done as ```bash #!/bin/bash name=$1 sudo ctr images check name==$name | ( read column_names read ref type digest others if [[ -z $ref ]]; then echo "$name: not found" exit 1 fi path="/var/lib/containerd/io.containerd.content.v1.content/blobs/${digest/:/\/}" notation verify --local --media-type $type $path ) ``` ## Open Questions 1. Should the `notation` CLI provide signing or verifying a descriptor directly without presenting the original manifest? - Note: Notary signature format may specific different hash algorithms for the descriptor.

    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