NakodaX

NakodaX blog/Source Protection·3 min read

How do you protect source code in a CI build?

Use the nkx tool in two steps around your normal build. First it decrypts the protected files your compiler needs. Your own compiler or bundler then runs as usual. Second, nkx encrypts the compiled output again, so the build you ship holds only encrypted files.

NakodaX Engineering team

By NakodaX Engineering team

NakodaX ·

A line of four glowing outline stations joined by a thin pipeline: a padlock, a laptop showing code, a second laptop showing code, and a second padlock.
Open the files for the build. Lock them again before you ship.

Most teams use CI, the automatic build that runs each time code is saved to a shared place. A build server needs to read your code to turn it into a program. If that code is protected, the build server has a problem. It cannot compile what it cannot read.

The answer is to open the files for a short time inside the build, then lock the result again before anything is shipped. This post shows how that works with nkx, the command line tool for Source Protection.

What does nkx do in a build?

nkx is a single program with nothing else to install. It runs on macOS, Linux and Windows. In a build it has two jobs, one before your compiler and one after it.

  1. Run nkx materialize before your compiler. It decrypts the protected files into a folder, so the compiler can read them.
  2. Run your own compiler or packaging tool, as you do today.
  3. Run nkx rehook after it. It encrypts the compiled TypeScript or JavaScript output again.
  4. Ship the result. The protected parts hold only encrypted files.

Make both steps a required stage of your pipeline, so every build you ship holds only encrypted files. The wider idea is described in protected release.

Which commands do you need?

These are the commands you will use most. Your NakodaX console shows the exact command and credentials for your own setup on the Connect page of a protected repository.

CommandWhat it does
nkx registerSets up credentials for a protected repository from a Register Token
nkx materializeIn CI, decrypts the protected files into a folder before your compiler runs
nkx rehookIn CI, encrypts the compiled TypeScript or JavaScript output again after your build
nkx unlockDecrypts protected files for editing in an approved change session
nkx resealEncrypts the files again and ends the session
nkx statusShows whether the repository is protected or unlocked

How do you install nkx and check the download?

On macOS and Linux, run brew install nakodax/tap/nkx. You can also download a file for macOS, Linux or Windows from the nkx releases page.

Every release file is signed with Sigstore cosign, and each release has a SHA256SUMS file. Compare your download with it before you use it. There is more on the developers page.

How do developers change protected code?

Developers do not use the build steps. They ask for a change session, and a different person approves it. Inside the session the developer runs nkx unlock, edits and tests the code, then runs nkx reseal to encrypt the files again and end the session.

nkx refuses to reseal if an unlocked file is staged in git, so readable code does not slip into a commit.

Contractors and vendors can work without any of this. They get stand ins, which have the same shape as the real files with placeholder bodies. See how this works for software companies.

What does this not do?

nkx does not run your protected software. The NakodaX runtime does that, a small library that sits inside your software, for Python or Node. nkx covers the build and the change session.

The build machine opens the files only for the length of the build, so run it on a machine you control.

It works today for Python, JavaScript, TypeScript and SQL, and more languages are planned.

The takeaway

Add two nkx steps around your normal build, and the build you ship holds only encrypted files for the protected parts.

Related product

NakodaX Source Protection

Let vendors and customers build or run software without receiving selected proprietary source code in readable form.

See how it works

Common questions

Do I need nkx for Python code?
Not for code that loads at run time. Python, JavaScript and TypeScript that load at run time need no extra build step. Projects that are bundled or compiled add the two nkx steps.
What happens if the second step is skipped?
Make the encrypt step a required stage of your pipeline, so every build you ship holds only encrypted files.
How do I know an nkx download is genuine?
Compare it with the SHA256SUMS file of the release, or verify its Sigstore cosign signature with the command in the release notes.

Try this on your own code.

Start a free trial, or tell us what you share and with whom, and we will show you how NakodaX handles it.