powershell-file-trust

CodeNotary allows to trust, untrust or unsupport any file, script or document on your system. Digital certificates only help with scripts and need to travel with the file itself. In real world scenarios your workflow consists of much more than the script, you typically have configuration files as well or other documents to use.

That blog post introduces the CodeNotary PowerShell repository that is home to some decent and easy to use PowerShell integrations:

  • notarize files with your identity and a certain trust level based on the directory you store them
  • authenticate files or scripts before you run or use them

PowerShell File Trust Watchdog

Let’s start with the CodeNotary PowerShell Watchdog, that listens to file creation events in a given directory and notarizes these files using your identity. CodeNotary can be used to substitute digital certificates. To get your identity simply get your free account here:

CodeNotary Free account

Use cases:

  • immutably notarize all files in a given directory, i. e. PowerShell scripts for production, configuration files, or documents
  • create a test, stage, production folder workflow by changing the script to watch each folder and adding a custom attribute when notarizing
  • create a trust, untrust, unsupport workflow by changing the script to watch each folder and notarize, untrust or unsupport the files when they move to the defined folder

Preparation

Make sure to install the CodeNotary vcn command that can be found here:

https://github.com/vchain-us/vcn/releases/latest

You can simply use the vcn setup for Microsoft Windows or alternatively download the vcn executable and store it locally. The location of vcn.exe needs to be configured in the script.

If you want to fully automate the watchdog, you need to set some environment variables. To do so, simply run sysdm.cpl using the Win+R shortcut:

PowerShell File Trust CodeNotary environment variabless

  • VCN_USER
  • VCN_PASSWORD
  • VCN_NOTARIZATION_PASSWORD

more information about the supported environmenment variables can be found here: https://docs.codenotary.io/vcn/user-guide/environments.html

Watch a single directory

Watching a single directory is pretty straightforward and you only need to change the $vcnpath, $watcher.path and if you want to check sub directories as well.

### Set vcn binary path - please download vcn here: https://github.com/vchain-us/vcn/releases/latest
   $vcnpath = """$env:programfilescodenotaryvcn.exe"""

### Set target directory and file types to watch for changes and if you want to include subdirectories
   $watcher = New-Object System.IO.FileSystemWatcher
     $watcher.Path = "C:UsersuserDocumentsNotarize"
   $watcher.IncludeSubdirectories = $true
   $watcher.EnableRaisingEvents = $true  

### Define notarization when files are detected
   $action = { $path = $Event.SourceEventArgs.FullPath
             $changeType = $Event.SourceEventArgs.ChangeType
     $param = " n " + """$Path""" + " --attr PSEvent=True"
     $command = $vcnpath + "$param"
            iex "& $command"
           $logline = "Notarized $(Get-Date), $changeType, $path"
           write-host $logline
          Add-content ($watcher.Path + "codenotary.log") -value $logline
              }    
### DECIDE WHICH EVENTS SHOULD BE WATCHED 
   Register-ObjectEvent $watcher "Created" -Action $action

   while ($true) {sleep 5}

Every time a file is stored within that directory a notarization of that file is processed and you can check your CodeNotary dashboard to get more details:

CodeNotary dashboard - check the File Trust level

Workflow environment based on folder structure

Let’s simply create the following folder structure:

  • Production (Trusted)
  • Old (unsupported)
  • Unwanted (Untrusted)

Based on the following script, files that are either created or moved in the corresponding folder get notarized with the chosen trust level.

file trust workflow

That way you can create a full workflow including an immutable trust level by simply moving files based on their lifecycle.

# Set vcn binary path - please download vcn here: https://github.com/vchain-us/vcn/releases/latest
   $vcnpath = """$env:programfilescodenotaryvcn.exe"""
   $logpath = "C:CodeNotarycodenotary.log"
## Define all environments

### Set Production environment
   $watchertrusted = New-Object System.IO.FileSystemWatcher
   $watchertrusted.Path = "C:CodeNotaryProduction"
   $watchertrusted.IncludeSubdirectories = $true
   $watchertrusted.EnableRaisingEvents = $true  

### Set Old environment
   $watcherunsupported = New-Object System.IO.FileSystemWatcher
   $watcherunsupported.Path = "C:CodeNotaryOld"
   $watcherunsupported.IncludeSubdirectories = $true
   $watcherunsupported.EnableRaisingEvents = $true  

### Set Unwanted environment
   $watcheruntrusted = New-Object System.IO.FileSystemWatcher
   $watcheruntrusted.Path = "C:CodeNotaryUnwanted"
   $watcheruntrusted.IncludeSubdirectories = $true
   $watcheruntrusted.EnableRaisingEvents = $true  

## Define notarization when files are detected
   $actiontrusted = { $path = $Event.SourceEventArgs.FullPath
             $changeType = $Event.SourceEventArgs.ChangeType
             $param = " notarize " + """$Path""" + " --attr PSEvent=True"
             $command = $vcnpath + "$param"
             iex "& $command"
             $logline = "Trust $(Get-Date), $changeType, $path"
             write-host $logline
             Add-content ($logpath) -value $logline
             }    

   $actionunsupported = { $path = $Event.SourceEventArgs.FullPath
             $changeType = $Event.SourceEventArgs.ChangeType
             $param = " unsupport " + """$Path""" + " --attr PSEvent=True"
             $command = $vcnpath + "$param"
             iex "& $command"
             $logline = "Unsupport $(Get-Date), $changeType, $path"
             write-host $logline
             Add-content ($logpath) -value $logline
             }    

   $actionuntrusted = { $path = $Event.SourceEventArgs.FullPath
             $changeType = $Event.SourceEventArgs.ChangeType
             $param = " untrust " + """$Path""" + " --attr PSEvent=True"
             $command = $vcnpath + "$param"
             iex "& $command"
             $logline = "Untrust $(Get-Date), $changeType, $path"
             write-host $logline
             Add-content ($logpath) -value $logline
             }    

# Register all Watcher
   Register-ObjectEvent $watchertrusted "Created" -Action $actiontrusted
   Register-ObjectEvent $watcherunsupported "Created" -Action $actionunsupported
   Register-ObjectEvent $watcheruntrusted "Created" -Action $actionuntrusted

   while ($true) {sleep 5}

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.