fully-trusted-gitlab-pipeline

As you noticed already, our goal is to make the CodeNotary integration as easy as possible for you. That’s the reason why our blog post series continues with GitLab. So far we covered Jenkins and CircleCI if you want to read them as well. For this blog post we use a GitLab CE installation.

This time we go one step further than the former posts and integrate a Git repository check as well.

The checks are going to look as follows:

  • Authenticate the Git repository
  • Build the container image based on the repository, if authentic
  • Notarize the container image before publishing
  • Publish the container image to your registry

Let’s get started!

Check our requirements first

As we only want to use notarized Git commits, we need a CodeNotary account and vcn locally installed next to git.

  1. CodeNotary Account (completely free)
  2. Download vcn & vcn login
  3. Setup the variables in your project for DockerHub and CodeNotary

environment variables for the pipeline

Setup the .gitlab-ci.yml

Like most CI/CD pipelines we start with the basic setup. Make sure to create the .gitlab-ci.yml file in your repository:

image: docker:18

stages:
  - authgit
  - build
  - notarize
  - push

variables:
    CONTAINER_IMAGE: "<dockerhub_repository_name>"

before_script:
  - echo -n $dockerhub_pass | docker login -u $dockerhub_user --password-stdin $dockerhub

Here we set the Container_image to the Dockerhub registry we want to use (i. e. user/image) and login to Dockerhub.com

Authenticate the sources

The next step is about authenticating the sources to make sure only notarized git commits are used during the build. In that post we use the vcn version 0.7.3, but you can use the latest of course.

Be aware, as we’re using an Alpine OS based image to use the static linked version of vcn.

Most importantly, we want to make sure, that nobody tampered with the vcn executable we downloaded, therefore we do an independent check using the CodeNotary.io API with curl.

# Authenticate Git source
Authenticate Git:
  stage: authgit
  script:
    - apk add --no-cache curl
    - curl -L -o /tmp/vcn https://github.com/vchain-us/vcn/releases/download/v0.7.3/vcn-v0.7.3-linux-amd64-static
    - CHECKSUM=$(sha256sum /tmp/vcn | cut -d " " -f 1)
    - echo $CHECKSUM
    - curl -s https://api.codenotary.io/authenticate/$CHECKSUM?org=vchain.us | grep -q :0
    - chmod +x /tmp/vcn
    - /tmp/vcn a git://$CI_PROJECT_DIR

vcn a git://$CI_PROJECT_DIR is used to authenticate the repository we use in that project pipeline.

For the pipeline to run later on, you always need to make sure to notarize the latest git commits.

Therefore, we need to pull the latest changes and notarize them, if we approve them:

  • git pull
  • vcn n git://repository-folder

Full Trust Gitlab repo notarization

Important: You should only use anonymous authentication when testing or working with private repositories. It’s highly recommended to use authenticate only with org or signer flags.

vcn a help:

  -I, --org string         accept only authentications matching the passed organisation's ID,
                           if set no SignerID can be used
                           (overrides VCN_ORG env var, if any)
  -s, --signerID strings   accept only authentications matching the passed SignerID(s)
                           (overrides VCN_SIGNERID env var, if any)

Build the image

We’re going to build the container image and push it just with the hash, but no additional tagging. That’s going to happen in a later step.

Build:
  stage: build
  script:
    - >
      docker build
      --pull
      --build-arg VCS_REF=$CI_COMMIT_SHA
      --build-arg VCS_URL=$CI_PROJECT_URL
      --tag $CONTAINER_IMAGE:$CI_COMMIT_SHA
      .
    - docker push $CONTAINER_IMAGE:$CI_COMMIT_SHA

Notarize the container image

That’s is mainly a copy of the authentication steps from the other build steps before. The reason is, that you can’t know if its just one or different GitLab Runner that pick up the tasks – so we make sure, they always are at the same stage:

# notarize container
Notarize:
  stage: notarize
  script:
    - apk add --no-cache curl
    - curl -L -o /tmp/vcn https://github.com/vchain-us/vcn/releases/download/v0.7.3/vcn-v0.7.3-linux-amd64-static
    - CHECKSUM=$(sha256sum /tmp/vcn | cut -d " " -f 1)
    - echo $CHECKSUM
    - curl -s https://api.codenotary.io/authenticate/$CHECKSUM?org=vchain.us | grep -q :0
    - chmod +x /tmp/vcn
    - VCN_USER=$codenotary_user VCN_PASSWORD=$codenotary_pass /tmp/vcn login
    - VCN_NOTARIZATION_PASSWORD=$codenotary_pass /tmp/vcn n --attr GitLab="$CI_COMMIT_SHA" docker://$CONTAINER_IMAGE:latest 

Push the image

The last steps are about pushing the newly build container image with different tags, the checksum (reference to the GitLab job) and latest.

# Here, the goal is to tag the "master" branch as "latest"
Push latest:
  variables:
    GIT_STRATEGY: none
  stage: push
  only:
    # Only "master" should be tagged "latest"
    - master
  script:
    # no guarantee that this job will be picked up by the same runner 
    # that built the image in the previous step, pull it again locally
    - docker pull $CONTAINER_IMAGE:$CI_COMMIT_SHA
    # Then we tag it "latest"
    - docker tag $CONTAINER_IMAGE:$CI_COMMIT_SHA $CONTAINER_IMAGE:latest
    # push it.
    - docker push $CONTAINER_IMAGE:latest

Push tag:
  variables:
    GIT_STRATEGY: none
  stage: push
  only:
    # run on tags only.
    - tags
  script:
    - docker pull $CONTAINER_IMAGE:$CI_COMMIT_SHA
    - docker tag $CONTAINER_IMAGE:$CI_COMMIT_SHA $CONTAINER_IMAGE:$CI_COMMIT_REF_NAME
    - docker push $CONTAINER_IMAGE:$CI_COMMIT_REF_NAME

Result

Make sure to notarize the repository commits, when changing the .gitlab-ci.yml file, as that change will also stop the container image from being build – Security first!

If all went well, you should be able to get nice green checks for every single pipeline step.

Trusted GitLab CI/CD

In another blog post we’ll also cover how you can auto-deploy into Kubernetes and use the Kube-Notary integration to make the 360 degree security cycle complete.

CNIL
Metrics and Logs

(formerly, Opvizor Performance Analyzer)

VMware vSphere & Cloud
PERFORMANCE MONITORING, LOG ANALYSIS, LICENSE COMPLIANCE!

Monitor and Analyze Performance and Log files:
Performance monitoring for your systems and applications with log analysis (tamperproof using immudb) and license compliance (RedHat, Oracle, SAP and more) in one virtual appliance!

Subscribe to Our Newsletter

Get the latest product updates, company news, and special offers delivered right to your inbox.

Subscribe to our newsletter

Use Case - Tamper-resistant Clinical Trials

Goal:

Blockchain PoCs were unsuccessful due to complexity and lack of developers.

Still the goal of data immutability as well as client verification is a crucial. Furthermore, the system needs to be easy to use and operate (allowing backup, maintenance windows aso.).

Implementation:

immudb is running in different datacenters across the globe. All clinical trial information is stored in immudb either as transactions or the pdf documents as a whole.

Having that single source of truth with versioned, timestamped, and cryptographically verifiable records, enables a whole new way of transparency and trust.

Use Case - Finance

Goal:

Store the source data, the decision and the rule base for financial support from governments timestamped, verifiable.

A very important functionality is the ability to compare the historic decision (based on the past rulebase) with the rulebase at a different date. Fully cryptographic verifiable Time Travel queries are required to be able to achieve that comparison.

Implementation:

While the source data, rulebase and the documented decision are stored in verifiable Blobs in immudb, the transaction is stored using the relational layer of immudb.

That allows the use of immudb’s time travel capabilities to retrieve verified historic data and recalculate with the most recent rulebase.

Use Case - eCommerce and NFT marketplace

Goal:

No matter if it’s an eCommerce platform or NFT marketplace, the goals are similar:

  • High amount of transactions (potentially millions a second)
  • Ability to read and write multiple records within one transaction
  • prevent overwrite or updates on transactions
  • comply with regulations (PCI, GDPR, …)


Implementation:

immudb is typically scaled out using Hyperscaler (i. e. AWS, Google Cloud, Microsoft Azure) distributed across the Globe. Auditors are also distributed to track the verification proof over time. Additionally, the shop or marketplace applications store immudb cryptographic state information. That high level of integrity and tamper-evidence while maintaining a very high transaction speed is key for companies to chose immudb.

Use Case - IoT Sensor Data

Goal:

IoT sensor data received by devices collecting environment data needs to be stored locally in a cryptographically verifiable manner until the data is transferred to a central datacenter. The data integrity needs to be verifiable at any given point in time and while in transit.

Implementation:

immudb runs embedded on the IoT device itself and is consistently audited by external probes. The data transfer to audit is minimal and works even with minimum bandwidth and unreliable connections.

Whenever the IoT devices are connected to a high bandwidth, the data transfer happens to a data center (large immudb deployment) and the source and destination date integrity is fully verified.

Use Case - DevOps Evidence

Goal:

CI/CD and application build logs need to be stored auditable and tamper-evident.
A very high Performance is required as the system should not slow down any build process.
Scalability is key as billions of artifacts are expected within the next years.
Next to a possibility of integrity validation, data needs to be retrievable by pipeline job id or digital asset checksum.

Implementation:

As part of the CI/CD audit functionality, data is stored within immudb using the Key/Value functionality. Key is either the CI/CD job id (i. e. Jenkins or GitLab) or the checksum of the resulting build or container image.

White Paper — Registration

We will also send you the research paper
via email.

CodeNotary — Webinar

White Paper — Registration

Please let us know where we can send the whitepaper on CodeNotary Trusted Software Supply Chain. 

Become a partner

Start Your Trial

Please enter contact information to receive an email with the virtual appliance download instructions.

Start Free Trial

Please enter contact information to receive an email with the free trial details.