<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.10.0">Jekyll</generator><link href="https://brokenco.de//feed/by_tag/jenkins.xml" rel="self" type="application/atom+xml" /><link href="https://brokenco.de//" rel="alternate" type="text/html" /><updated>2026-10-31T17:58:32+00:00</updated><id>https://brokenco.de//feed/by_tag/jenkins.xml</id><title type="html">rtyler</title><subtitle>a moderately technical blog</subtitle><author><name>R. Tyler Croy</name></author><entry><title type="html">Self-hosting Jenkins and Gitea</title><link href="https://brokenco.de//2026/10/18/self-hosting-jenkins.html" rel="alternate" type="text/html" title="Self-hosting Jenkins and Gitea" /><published>2026-10-18T00:00:00+00:00</published><updated>2026-10-18T00:00:00+00:00</updated><id>https://brokenco.de//2026/10/18/self-hosting-jenkins</id><content type="html" xml:base="https://brokenco.de//2026/10/18/self-hosting-jenkins.html"><![CDATA[<p>I consider learning how to script or automate things among the most important
investments developers can make early in their career. The progression for a
lot of people was learning to write scripts and then learning how to run those
scripts with <code class="language-plaintext highlighter-rouge">cron</code>. <strong>Go further</strong>.</p>

<p>At least once a week I derive <em>some</em> benefit from the investment in time
I had a few years ago in in my <a href="https://about.gitea.com/">Gitea</a> and
<a href="https://jenkins.io">Jenkins</a> home lab.</p>

<p>At the outset, I used the <a href="https://docs.gitea.com/usage/repository/repo-mirror/">mirror
repository</a>
functionality of Gitea combined with the <a href="https://plugins.jenkins.io/gitea/">Gitea
plugin</a> for Jenkins to make it trivial to
keep LAN-local copies of key dependencies</p>

<p>As my needs evolved I ended up with numerous pipelines which do <em>things</em>.
Various automations when new tags are introduced in upstream repositories,
integration testing of my key tools, or validating correctness of my own
projects.</p>

<p>Many of the use-cases I have can be solved on a public forge like GitHub or GitLab <em>however</em> the local nature of my setup affords a number of benefits:</p>

<ul>
  <li>I am uninhibited in trying all sorts of wacky things because <em>nobody but me
will see</em>.</li>
  <li>Task execution is as far as my local hardware (your mileage may vary).</li>
  <li>I don’t need to consider public/private visibility, it’s all personal until
otherwise determined.</li>
</ul>

<p>Despite all the hype around <em>agentic development</em>, many would be surprised at
how productivity gains that can be gained by the incremental compound interest
of investing in <em>personal automation</em> with run of the mill scripting and CI.</p>

<p>I recommend learning the <a href="https://www.jenkins.io/doc/book/pipeline/syntax/">Jenkins Pipeline
syntax</a>, deploying a local
Gitea (or Forgejo), and starting to automate the many little things that will
benefit your day-to-day software development.</p>]]></content><author><name>R. Tyler Croy</name></author><category term="jenkins" /><category term="software" /><summary type="html"><![CDATA[I consider learning how to script or automate things among the most important investments developers can make early in their career. The progression for a lot of people was learning to write scripts and then learning how to run those scripts with cron. Go further.]]></summary></entry><entry><title type="html">Parsing Jenkins Pipeline without Jenkins</title><link href="https://brokenco.de//2020/12/25/jenkins-declarative-parser.html" rel="alternate" type="text/html" title="Parsing Jenkins Pipeline without Jenkins" /><published>2020-12-25T00:00:00+00:00</published><updated>2020-12-25T00:00:00+00:00</updated><id>https://brokenco.de//2020/12/25/jenkins-declarative-parser</id><content type="html" xml:base="https://brokenco.de//2020/12/25/jenkins-declarative-parser.html"><![CDATA[<p>Writing and locally verifying a CI/CD pipeline is a challenge thousands of
developers face, which I’m hoping to make a little bit easier with a new tool
named: <a href="https://github.com/rtyler/jdp">Jenkins Declarative Parser</a> (<code class="language-plaintext highlighter-rouge">jdp</code>).
Jenkins Pipeline is one of the most important advancements made in the last 10
years for Jenkins, it can however behave like a frustrating black box for many
new and experienced Jenkins users. The goal with <code class="language-plaintext highlighter-rouge">jdp</code> is to provide a
lightweight and easy to run utility and library for validating declarative
Jenkinsfiles.</p>

<hr />

<p>If you have <code class="language-plaintext highlighter-rouge">cargo</code> installed, you can get <code class="language-plaintext highlighter-rouge">jdp</code> right now by running <code class="language-plaintext highlighter-rouge">cargo
install jdp</code>, or you can download a Linux/amd64-based binary from the
<a href="https://github.com/rtyler/jdp/releases/tag/v0.2.2">releases</a>.</p>

<hr />

<p>Within the Jenkins advocacy group, I think the biggest marketing coup we have
accomplished to date is making people think that “Declarative Pipeline” is
<em>actually</em> declarative. For better or worse, it’s really not. There is no
first-party grammar or parser for a declarative <code class="language-plaintext highlighter-rouge">Jenkinsfile</code>. The dirty little
secret is that Declarative Pipeline is just a <a href="https://groovy-lang.org">Groovy</a>
domain specific language, one which tries to hide Groovy from the user, but in
many cases fails to do so. Personally, I still think Declarative is a <em>much</em>
better option than Scripted, with far more guardrails which  help keep users
working with best practices. As I have gotten deep into the supported syntax of
Declarative however, I have started to see numerous holes in the thin veneer
over Groovy.</p>

<p>As of now, <code class="language-plaintext highlighter-rouge">jdp</code> is at v0.2.2 and can support <em>lots</em> of Declarative Pipeline
syntax.</p>

<p>This parser is not a Groovy syntax parser and as such any advanced or wacky
groovy that is littered around a Jenkinsfile will be ignored. This
includes the <code class="language-plaintext highlighter-rouge">script</code> step which is basically checked to make sure that there is
a <code class="language-plaintext highlighter-rouge">script { }</code> block, but anything within it is explicitly ignored.</p>

<p>Here’s an example of a non-trivial pipeline pulled from the Jenkins documentation:</p>

<div class="language-groovy highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">pipeline</span> <span class="o">{</span>
    <span class="n">agent</span> <span class="n">any</span>
    <span class="n">stages</span> <span class="o">{</span>
        <span class="n">stage</span><span class="o">(</span><span class="s1">'Example Build'</span><span class="o">)</span> <span class="o">{</span>
            <span class="n">steps</span> <span class="o">{</span>
                <span class="n">echo</span> <span class="s1">'Hello World'</span>
            <span class="o">}</span>
        <span class="o">}</span>
        <span class="n">stage</span><span class="o">(</span><span class="s1">'Example Deploy'</span><span class="o">)</span> <span class="o">{</span>
            <span class="n">when</span> <span class="o">{</span>
                <span class="n">branch</span> <span class="s1">'production'</span>
            <span class="o">}</span>
            <span class="n">steps</span> <span class="o">{</span>
                <span class="n">echo</span> <span class="s1">'Deploying'</span>
            <span class="o">}</span>
        <span class="o">}</span>
    <span class="o">}</span>
<span class="o">}</span>
</code></pre></div></div>

<p>When <code class="language-plaintext highlighter-rouge">jdp check</code> is executed against this file, it let’s me know that it’s correct!</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>❯ jdp check data/valid/when-branch/Jenkinsfile
Looks valid! Great work!
</code></pre></div></div>

<p>The <code class="language-plaintext highlighter-rouge">jdp check</code> tries to be as helpful as possible with bad syntax or semantics
in an invalid <code class="language-plaintext highlighter-rouge">Jenkinsfile</code>. This is an area that I want to improve more, with
<code class="language-plaintext highlighter-rouge">rustc</code> as a good inspiration for how helpful a “compiler” or “linter” should
behave:</p>

<div class="language-groovy highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">pipeline</span> <span class="o">{</span>
    <span class="n">agent</span> <span class="n">any</span>
    <span class="n">stages</span> <span class="o">{</span>
        <span class="n">stage</span><span class="o">(</span><span class="s1">'Build'</span><span class="o">)</span> <span class="o">{</span>
        <span class="o">}</span>
    <span class="o">}</span>
<span class="o">}</span>
</code></pre></div></div>

<p>The above pipeline doesn’t have syntax errors, but does lack some important
semantics required by a Declarative Jenkinsfile:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>jdp check data/invalid/no-steps-in-stage/Jenkinsfile 

data/invalid/no-steps-in-stage/Jenkinsfile
------------------------------------------
0: pipeline {
1:     agent any
2:     stages {
3:         stage('Build') {
  --------^

Fail: A stage must have either steps{}, parallel{}, or nested stages {}
</code></pre></div></div>

<hr />

<p>There are still <em>tons</em> of things I want to do with <code class="language-plaintext highlighter-rouge">jdp</code>, which is written in
Rust. If you’re keen on building a first-class <code class="language-plaintext highlighter-rouge">Jenkinsfile</code> grammar or
development tooling: check out the <a href="https://github.com/rtyler/jdp/issues">issues
page</a> for some of the ideas I have in
mind for <code class="language-plaintext highlighter-rouge">jdp</code>.</p>

<p>As we enter 2021, Jenkins Pipeline will definitely continue to play a major
role in many of our CI/CD pipelines. With <code class="language-plaintext highlighter-rouge">jdp</code>, I’m hoping it becomes a bit
easier for us all to write high quality and correct Jenkinsfiles!</p>]]></content><author><name>R. Tyler Croy</name></author><category term="jenkins" /><category term="rust" /><category term="otto" /><category term="pipeline" /><summary type="html"><![CDATA[Writing and locally verifying a CI/CD pipeline is a challenge thousands of developers face, which I’m hoping to make a little bit easier with a new tool named: Jenkins Declarative Parser (jdp). Jenkins Pipeline is one of the most important advancements made in the last 10 years for Jenkins, it can however behave like a frustrating black box for many new and experienced Jenkins users. The goal with jdp is to provide a lightweight and easy to run utility and library for validating declarative Jenkinsfiles.]]></summary></entry><entry><title type="html">Sketches of syntax, a pipeline for Otto</title><link href="https://brokenco.de//2020/11/06/pipeline-syntax-for-otto.html" rel="alternate" type="text/html" title="Sketches of syntax, a pipeline for Otto" /><published>2020-11-06T00:00:00+00:00</published><updated>2020-11-06T00:00:00+00:00</updated><id>https://brokenco.de//2020/11/06/pipeline-syntax-for-otto</id><content type="html" xml:base="https://brokenco.de//2020/11/06/pipeline-syntax-for-otto.html"><![CDATA[<p>Defining a good continuous integration and delivery pipeline syntax for
<a href="https://github.com/rtyler/otto">Otto</a> is one of the most important
challenges in the entire project. It is one which I struggled with early in
the project almost a year and a half ago. It is a challenge I continue to
struggle with today, even as the puzzles pieces start to interlock for the
multi-service system I originally imagined Otto to be. Now that I have started
writing the parser, the pressure to make some design decisions and play them
out to their logical ends is growing. The following snippet compiles to the
<em>current</em> Otto intermediate representation and will execute on the <em>current</em>
prototype agent implementation:</p>

<div class="language-groovy highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">pipeline</span> <span class="o">{</span>
  <span class="n">stages</span> <span class="o">{</span>
    <span class="n">stage</span> <span class="o">{</span>
      <span class="n">name</span> <span class="o">=</span> <span class="s1">'Build'</span>
      <span class="n">steps</span> <span class="o">{</span>
        <span class="n">echo</span> <span class="s1">'&gt;&gt; Building project'</span>
        <span class="n">sh</span> <span class="s1">'make all'</span>
      <span class="o">}</span>
    <span class="o">}</span>
  <span class="o">}</span>
<span class="o">}</span>
</code></pre></div></div>

<p>“It works!”</p>

<p>The reaction upon sharing this with friends and colleagues on Twitter was
largely: “looks like Declarative [Pipeline].” The syntax above is just a simple
shim to get the basics working, but the similarities are no accident. <a href="https://jenkins.io/doc/book/pipeline/syntax/">Jenkins
Pipeline</a> is the best publicly
available syntax for describing a CI/CD pipeline (in my not-so-humble opinion).
If I didn’t believe that I wouldn’t continue to advocate for its use at every
possible turn.</p>

<p>For Otto however, the goal is not to create a Jenkins Pipeline knock-off. In
this post I wanted to share some sketches of what I think Otto Pipelines should
look like and why. For starters, the README <a href="https://github.com/rtyler/otto/tree/3c2daa412ab091d827040c56f891ad0fdcd7cd2c#modeling-continuous-delivery">has an incomplete
list</a>
covering some high-level goals that I have for modeling continuous delivery. The <a href="https://github.com/rtyler/otto/tree/3c2daa412ab091d827040c56f891ad0fdcd7cd2c/examples">examples/
directory</a>
also has a few sample <code class="language-plaintext highlighter-rouge">.otto</code> files which I will use for reference throughout
this post.</p>

<p>It may also be worth reading my previous post describing <a href="/2020/10/18/otto-steps.html">Step
Libraries</a> if you haven’t already, since they play
an integral part in making this syntax “go.”</p>

<p>With the pre-requisites out of the way, let’s walk through some syntax!</p>

<h2 id="defining-the-available-tools">Defining the available tools</h2>

<div class="language-groovy highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">use</span> <span class="o">{</span>
  <span class="n">stdlib</span>
  <span class="s1">'./common/slack'</span>
<span class="o">}</span>
</code></pre></div></div>

<p>Sprinkled at the top of Otto Pipelines is the <code class="language-plaintext highlighter-rouge">use</code> block. A common problem
with Jenkins Pipeline is that the steps available in the <code class="language-plaintext highlighter-rouge">Jenkinsfile</code> is
completely dependent on what plugins have been installed on the controller <em>or</em>
what <a href="https://jenkins.io/doc/book/pipeline/shared-libraries/">Shared Libraries</a>
have been configured. The <code class="language-plaintext highlighter-rouge">use</code> block effectively brings Otto Step Libraries
into scope for the given pipeline. Because Step Libraries require no
“controller-side” execution in Otto, each Otto Pipeline can use a completely
different sets of steps for users to leverage in their workflow.</p>

<p><strong>Open questions</strong>:</p>

<ul>
  <li>Versioning for step libraries seems like it is worth doing, but what’s the right syntax for expressing it?</li>
  <li>Referring to step libraries by URL could be incredibly useful, but is it worth the complexity?</li>
</ul>

<h2 id="defining-the-execution-environment">Defining the execution environment</h2>

<p>Next is declaring the execution environment for a stage/stages:</p>

<div class="language-groovy highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="cm">/* snip */</span>
<span class="n">stage</span> <span class="o">{</span>
  <span class="n">name</span> <span class="o">=</span> <span class="s1">'Build'</span>

  <span class="n">runtime</span> <span class="o">{</span>
    <span class="n">docker</span> <span class="o">{</span>
      <span class="n">image</span> <span class="o">=</span> <span class="s1">'ruby:2.6'</span>
    <span class="o">}</span>
  <span class="o">}</span>

  <span class="n">steps</span> <span class="o">{</span>
  <span class="o">}</span>
<span class="o">}</span>
</code></pre></div></div>

<p>Resource allocation is one of the areas I am most excited to explore with Otto,
but from a modeling standpoint and an execution standpoint. Jenkins was build
before “cloud” was a thing, and arguably before “containers”, depending on
whether or not any rabid Solaris users are within earshot. As such it has some
pitfalls when mapping pipeline execution to these much more dynamic
environments. On the flip side, newer CI/CD systems seem to have all gravitated
towards container-all-the-things and typically don’t consider non-container
workloads in any form, and will also usually require a Kubernetes clusters just
to get started.</p>

<div class="language-groovy highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">runtime</span> <span class="o">{</span>
  <span class="n">arch</span> <span class="o">=</span> <span class="s1">'amd64'</span>
  <span class="n">linux</span> <span class="o">{</span>
    <span class="n">pkgconfig</span> <span class="o">=</span> <span class="o">[</span><span class="s1">'openssl'</span><span class="o">,</span> <span class="s1">'libxml-2.0'</span><span class="o">]</span>
  <span class="o">}</span>
  <span class="n">python</span> <span class="o">{</span>
    <span class="n">version</span> <span class="o">=</span> <span class="s1">'~&gt; 3.8.5'</span>
    <span class="n">virtualenv</span> <span class="o">=</span> <span class="kc">true</span>
  <span class="o">}</span>
<span class="o">}</span>
</code></pre></div></div>

<p>For Otto I want to do <em>better</em> and started thinking about <em>capabilities</em> rather
than fixed labels or names. In many cases, I don’t particularly care where my
Rust project builds, just so long as it has <code class="language-plaintext highlighter-rouge">cargo</code> and an up-to-date stable
<code class="language-plaintext highlighter-rouge">rustc</code>. Similarly for Python projects, I might need an execution environment
with Python 3.x, <code class="language-plaintext highlighter-rouge">virtualenv</code>, and <code class="language-plaintext highlighter-rouge">libxml2</code> installed. In most systems that
precede Otto, administrators end up defining complex labels which users must
know. Another way to paper over this complexity is to say “just bring your own
container!” which pushes a lot of work back onto developers, typically leading
to one-off <code class="language-plaintext highlighter-rouge">Dockerfile</code>s which just take an upstream image and add one or two
dependencies.</p>

<p>With a capabilities-oriented model, the pipeline orchestration layer is no
longer looking for machines labeled “linux-python” or and then hoping one is
available. Instead the orchestrator can be smarter and find any available
capacity to meet the capabilities request.  I believe this approach can improve
on overall system performance and scheduling. An idea which I have floating
around as <a href="https://github.com/rtyler/otto/blob/main/rfc/0003-resource-auctioning.adoc">a draft
RFC</a>
right now is basically to “auction” pipeline tasks to the lowest bidder. When I
first started considering this idea, I found this paper titled <a href="https://www.scribd.com/document/439692166/Efficient-Nash-Equilibrium-Resource-Allocation-Based-on-Game-Theory-Mechanism-in-Cloud-Computing-by-Using-Auction">Efficient Nash
Equilibrium Resource Allocation Based on Game Theory Mechanism in Cloud
Computing by Using
Auction</a>,
which will likely guide the implementation of <code class="language-plaintext highlighter-rouge">auctioneer</code> quite a bit.</p>

<p>What remains to be seen is whether users are actually interested in
<em>expressing</em> the capabilities that would be necessary to make a highly
efficient resource auction practical.</p>

<p><strong>Open questions:</strong></p>

<ul>
  <li>Do most developers think about what their pipeline needs in the same way I think about capabilities?</li>
  <li>How would an administrator define capabilities of a cloud-based VM template?</li>
</ul>

<h2 id="caching">Caching</h2>

<p>From an operational standpoint, I think the most common problem of <em>any</em> CI
system is overuse of remote resources by pipelines. <a href="https://twitter.com/technosophos/status/1324037674588463105">This is not a niche
problem</a>, but
rather something that affects practically everybody. Some will say “you should
be caching and proxying all your remote resources!” which is simply not a
practical solution for the vast majority of the users in the ecosystem. Many at
users won’t be at organizations large enough to deploy such caching proxies.</p>

<div class="language-groovy highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">stage</span> <span class="o">{</span>
  <span class="n">name</span> <span class="o">=</span> <span class="s1">'Build'</span>

  <span class="n">cache</span> <span class="o">{</span>
    <span class="c1">// Create a cache named "gems", immutable for the rest of the Pipeline</span>
    <span class="n">gems</span> <span class="o">=</span> <span class="o">[</span><span class="s1">'vendor/'</span><span class="o">]</span>
    <span class="n">assets</span> <span class="o">=</span> <span class="o">[</span><span class="s1">'dist/css/'</span><span class="o">,</span> <span class="s1">'dist/js/'</span><span class="o">]</span>
  <span class="o">}</span>

  <span class="cm">/* snip */</span>
<span class="o">}</span>
<span class="n">stage</span> <span class="o">{</span>
  <span class="n">name</span> <span class="o">=</span> <span class="s1">'Test'</span>
  <span class="n">cache</span> <span class="o">{</span>
    <span class="n">use</span> <span class="n">gems</span>
  <span class="o">}</span>
<span class="o">}</span>
</code></pre></div></div>

<p>The <code class="language-plaintext highlighter-rouge">cache</code> block is intended to provide pipeline authors with a way to cache
arbitrary sections of the workspace for later re-use in the pipeline across
multiple agents. This is a pretty simple syntax addition, but something built
into the Otto infrastructure from the beginning.</p>

<p>On the implementation side, this requires that archiving and retrieving these
artifacts is relatively quick, which I don’t believe will be a major challenge.</p>

<p><strong>Open questions:</strong></p>

<ul>
  <li>Is it sufficient to cache a file subtree and simply restore it into the same
location in another agent’s workspace?</li>
  <li>Would this syntax accommodate the caching of Docker image layers?</li>
</ul>

<h2 id="composition-and-re-use">Composition and Re-use</h2>

<p>Inevitably developers try to abstract common functionality and behaviors into
re-usable components. Step Libraries can provide one flavor of this
re-usability, but I don’t believe that it is sufficient. The ubiqitous adoption
of YAML by newer CI/CD tools lead me to joke about <a href="/2018/08/15/five-stages-of-yaml.html">the five stages of
YAML</a> wherein developers end up turning a
declarative syntax into templates and then into just another turing-complete
language.</p>

<p>In Jenkins we have seen numerous tools for templatizing jobs, pipelines, or
other aspects of Jenkins configuration. Suffice it to say, there is a need to
compose and re-use various aspects of pipelines.</p>

<p>For Otto, I have been playing around with a context-aware <code class="language-plaintext highlighter-rouge">from</code> keyword, such as below:</p>

<div class="language-groovy highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">stage</span> <span class="o">{</span>
  <span class="n">name</span> <span class="o">=</span> <span class="s1">'Test'</span>
  <span class="n">runtime</span> <span class="o">{</span>
    <span class="n">from</span> <span class="s1">'Build'</span>
  <span class="o">}</span>
  <span class="n">steps</span> <span class="o">{</span>
    <span class="n">sh</span> <span class="s1">'bundle exec rake spec'</span>
  <span class="o">}</span>
<span class="o">}</span>
</code></pre></div></div>

<p>In the above example, <code class="language-plaintext highlighter-rouge">from</code> instructs the pipeline to re-use the contents of
the runtime block from the <code class="language-plaintext highlighter-rouge">Build</code> stage. My current thinking is that this
simple use of <code class="language-plaintext highlighter-rouge">from</code> allows for pipeline-internal re-use of pieces without the
need to set variables or turn this into a scripting language.</p>

<p>That said, re-usability within the pipeline isn’t where the main interest in
“templates” lies.</p>

<p>I have been exploring the concept of a “blueprint” which can act as an
re-usable unit of Otto Pipeline. I am imagining that these would be published
and managed similarly to Step Libraries. In order to provide maximum
flexibility, I think blueprints should be able to capture just about any
snippet of the Otto Pipeline syntax for re-use, consider the following example
to help make common Ruby gem build/test/publish pipelines cleaner:.</p>

<p><strong>rubygem.blueprint</strong></p>
<div class="language-groovy highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">use</span> <span class="o">{</span>
  <span class="n">stdlib</span>
<span class="o">}</span>

<span class="n">blueprint</span> <span class="o">{</span>
  <span class="n">parameters</span> <span class="o">{</span>
    <span class="n">rubyVersion</span> <span class="o">{</span>
      <span class="n">description</span> <span class="o">=</span> <span class="s1">'Specify the Ruby container'</span>
      <span class="k">default</span> <span class="o">=</span> <span class="s1">'ruby'</span>
      <span class="n">type</span> <span class="o">=</span> <span class="n">string</span>
    <span class="o">}</span>

    <span class="n">deploy</span> <span class="o">{</span>
      <span class="n">description</span> <span class="o">=</span> <span class="s1">'Push to rubygems.oorg'</span>
      <span class="k">default</span> <span class="o">=</span> <span class="kc">true</span>
      <span class="n">type</span> <span class="o">=</span> <span class="kt">boolean</span>
    <span class="o">}</span>
  <span class="o">}</span>

  <span class="n">plan</span> <span class="o">{</span>
    <span class="n">stages</span> <span class="o">{</span>
      <span class="n">stage</span><span class="o">(</span><span class="s1">'Build'</span><span class="o">)</span> <span class="o">{</span>
        <span class="n">runtime</span> <span class="o">{</span>
          <span class="n">docker</span> <span class="o">{</span>
            <span class="n">image</span> <span class="o">=</span> <span class="n">vars</span><span class="o">.</span><span class="na">rubyVersion</span>
          <span class="o">}</span>
        <span class="o">}</span>

        <span class="n">steps</span> <span class="o">{</span>
          <span class="n">sh</span> <span class="s1">'bundle install'</span>
          <span class="n">sh</span> <span class="s1">'bundle exec rake build'</span>
        <span class="o">}</span>
      <span class="o">}</span>

      <span class="n">stage</span><span class="o">(</span><span class="s1">'Test'</span><span class="o">)</span> <span class="o">{</span>
        <span class="n">runtime</span> <span class="o">{</span> <span class="n">from</span> <span class="s1">'Build'</span> <span class="o">}</span>
        <span class="n">steps</span> <span class="o">{</span>
          <span class="n">sh</span> <span class="s1">'bundle exec rake test'</span>
        <span class="o">}</span>
      <span class="o">}</span>

      <span class="n">stage</span><span class="o">(</span><span class="s1">'Deploy'</span><span class="o">)</span> <span class="o">{</span>
        <span class="n">gates</span> <span class="o">{</span> <span class="n">enter</span> <span class="o">{</span> <span class="n">vars</span><span class="o">.</span><span class="na">deploy</span> <span class="o">}</span> <span class="o">}</span>
        <span class="n">runtime</span> <span class="o">{</span> <span class="n">from</span> <span class="s1">'Build'</span> <span class="o">}</span>
        <span class="n">steps</span> <span class="o">{</span>
          <span class="n">sh</span> <span class="s1">'bundle exec rake push'</span>
        <span class="o">}</span>
      <span class="o">}</span>
    <span class="o">}</span>
  <span class="o">}</span>
<span class="o">}</span>
</code></pre></div></div>

<p>This would then be later re-used within an Otto Pipeline by using the same <code class="language-plaintext highlighter-rouge">from</code> syntax as before:</p>

<div class="language-groovy highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">pipeline</span> <span class="o">{</span>
  <span class="n">from</span> <span class="s1">'blueprints/rubygem'</span>

  <span class="cm">/*
   * Optionally I could add additional post-deployment configuration here,
   * which would be ordered after the blueprint's stages have completed
   */</span>
<span class="o">}</span>
</code></pre></div></div>

<p>Since <code class="language-plaintext highlighter-rouge">from</code> would be somewhat context-aware and would be able to pull all the
right stages “into place” within the pipeline. I’m optimistic that this
approach would allow the definition that includes just one stage for example,
or other blocks which can be defined within the <code class="language-plaintext highlighter-rouge">pipeline { }</code>.</p>

<p>I am not yet sure what the right mechanism for passing parameters into the
blueprint should be. Right now I am leaning towards keyword arguments on the
<code class="language-plaintext highlighter-rouge">from</code> directive: <code class="language-plaintext highlighter-rouge">from blueprint: 'blueprints/rubygem', rubyVersion: '2.6',
deploy: false</code>.I am not really sure what the implementation complexity of this
approach will bring however.</p>

<p><strong>Open Questions:</strong></p>

<ul>
  <li>Will treating <code class="language-plaintext highlighter-rouge">from</code> almost like a preprocessor directive allow the parser to successfully handle blueprints for arbitrary blocks of pipeline?</li>
  <li>Does this amount of composition alleviate the pressure that templates tend to solve for other systmes?</li>
</ul>

<h2 id="gates">Gates</h2>

<p>The final bit of syntax I wish to discuss at the moment are “gates.” One of the
least appreciated parts of just about every CD pipeline, gates define how the
pipeline should behave differently under certain conditions, including pausing
for user input or an external event.</p>

<p>From one of the modeling goals I had set:</p>

<blockquote>
  <p><strong>External interactions must be model-able.</strong> Deferring control to an external
system must be accounted for in a user-defined model. For example, submitting
a deployment request, and then waiting for some external condition to be made
to indicate that the deployment has completed and the service is now online.
This should support both an evented model, wherein the external service
“calls back” and a polling model, where the process waits until some external
condition can be verified.</p>
</blockquote>

<p>A contrived example of what this might look like for a pipeline which prepares
a deployment whenever changes land in the <code class="language-plaintext highlighter-rouge">main</code> branch:</p>

<div class="language-groovy highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">gates</span> <span class="o">{</span>
  <span class="n">enter</span> <span class="o">{</span> <span class="n">branch</span> <span class="o">==</span> <span class="s1">'main'</span> <span class="o">}</span>

  <span class="cm">/*
  * The exit block is where external stimuli back into the system
  * should be modeled, providing some means of holding back the pipeline
  * until the condition has been met
  */</span>
  <span class="n">exit</span> <span class="o">{</span>
    <span class="n">input</span> <span class="s1">'Does staging look good to you?'</span>
  <span class="o">}</span>
<span class="o">}</span>
</code></pre></div></div>

<p>Of anything discussed thus far, gates have the <em>most</em> runtime implementation requirements. In the primitive example above we have:</p>

<ul>
  <li>A Git branch being referenced, which needs to be pulled into scope somehow/somewhere.</li>
  <li>An expression that needs to be evaluated in the service mesh before this stage of the pipeline is dispatched.</li>
  <li>An <code class="language-plaintext highlighter-rouge">input</code> step which should allow the agent which executed the stage to
deallocate <strong>and</strong> pause further execution of the pipeline until some
external event is provided.</li>
</ul>

<p>The last item is the most challenging for me to think about from an
implementation and modeling standpoint. Somewhere within Otto a state machine
for each pipeline must be maintained, and once an <code class="language-plaintext highlighter-rouge">input</code>, <code class="language-plaintext highlighter-rouge">webhook</code>, or some
other step is encountered, the state machine must pause for external actions.
How those external actions should be wired in? Not sure! How those steps should
be defined? Not sure!</p>

<p>There are so many open questions at this point.</p>

<p>Gates leave me with the most discomfort of any of my ideas for Otto. Done well,
gates could provide a key component missing from many existing tools. The
challenge is going to be finding the space between the pipeline modeling
language and the execution engine which will accommodate them.</p>

<hr />

<p>I still probably have more questions than answers at this point about how the
pipeline modeling syntax should be defined and how it should execute. The one
major lesson which I have learned from my time in the Jenkins project is that
the pipeline syntax cannot be improved in isolation from the execution
environment. There are many key design decisions which need to be made in both
domains which will have major repercussions in the other.</p>

<p>I think back to the word used by a developer who read my thoughts on what I
want to do with Otto:</p>

<p>“<strong>Ambitious</strong>.”</p>

<hr />

<p>As always, if you’re curious to learn more, you’re welcome to join <code class="language-plaintext highlighter-rouge">#otto</code> on the
<a href="https://freenode.net">Freenode</a> IRC network, or follow along on
<a href="https://github.com/rtyler/otto">GitHub</a></p>]]></content><author><name>R. Tyler Croy</name></author><category term="otto" /><category term="jenkins" /><category term="pipeline" /><category term="cicd" /><category term="ci" /><summary type="html"><![CDATA[Defining a good continuous integration and delivery pipeline syntax for Otto is one of the most important challenges in the entire project. It is one which I struggled with early in the project almost a year and a half ago. It is a challenge I continue to struggle with today, even as the puzzles pieces start to interlock for the multi-service system I originally imagined Otto to be. Now that I have started writing the parser, the pressure to make some design decisions and play them out to their logical ends is growing. The following snippet compiles to the current Otto intermediate representation and will execute on the current prototype agent implementation:]]></summary></entry><entry><title type="html">Building containers in Jenkins with Kaniko</title><link href="https://brokenco.de//2019/10/03/kanikosan.html" rel="alternate" type="text/html" title="Building containers in Jenkins with Kaniko" /><published>2019-10-03T00:00:00+00:00</published><updated>2019-10-03T00:00:00+00:00</updated><id>https://brokenco.de//2019/10/03/kanikosan</id><content type="html" xml:base="https://brokenco.de//2019/10/03/kanikosan.html"><![CDATA[<p>I have a love/hate relationship with containers. We have used containers for
production services in the Jenkins project’s
<a href="https://github.com/jenkins-infra">infrastructure</a> for six or seven years,
where they have been very useful. I run some desktop applications <a href="https://gist.github.com/rtyler/767cfab0e50d7d79100b52cf0a13427a">in
containers</a>.
There are even a few Kubernetes clusters which show the tell-tale signs of my
usage. Containers are great. Not a week goes by however when some oddity in
containers, or the tools around them, throws a wrench into the gears and causes
me great frustration. This week was one of those weeks: we suddenly had
problems building our Docker containers in one of our Kubernetes environments.</p>

<p>I’m a strong supporter of running Jenkins workloads in Kubernetes for a myriad
of reasons, which I won’t go into here. Like most organizations however, we
don’t just need containers for the testing of our applications, we need to
package them into containers as well. As such, we need to build Docker
containers atop Kubernetes, which isn’t as straight-forward as you might hope.</p>

<p>For years I have followed the same approach that <a href="https://medium.com/hootsuite-engineering/building-docker-images-inside-kubernetes-42c6af855f25">Hoot Suite describes in this
post</a>,
utilizing Docker’s own “Docker in Docker” container (<code class="language-plaintext highlighter-rouge">docker:dind</code>). By <a href="https://gist.github.com/rtyler/14a43e3c2c21d876d3f6315b1e82bc25">using
a pod with Docker-in-Docker and a Docker client
container</a>,
the <code class="language-plaintext highlighter-rouge">Jenkinsfile</code> can be <em>fairly</em> simple for building a container but certainly
not as simple as a plain <code class="language-plaintext highlighter-rouge">sh 'docker build rofl:copter'</code>. With the linked
configuration above, our pipelines would typically have an explicit stage which
would build Docker containers:</p>

<div class="language-groovy highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">pipeline</span> <span class="o">{</span>
    <span class="n">stages</span> <span class="o">{</span>
        <span class="n">stage</span><span class="o">(</span><span class="s1">'Buildo Roboto'</span><span class="o">)</span> <span class="o">{</span>
            <span class="n">agent</span> <span class="o">{</span> 
                <span class="n">kubernetes</span> <span class="o">{</span>
                    <span class="n">label</span> <span class="s1">'docker'</span>
                    <span class="n">defaultContainer</span> <span class="s1">'docker'</span>
                <span class="o">}</span>
            <span class="o">}</span>
            <span class="n">steps</span> <span class="o">{</span>
                <span class="n">sh</span> <span class="s1">'docker build -t roboto:latest'</span>
            <span class="o">}</span>
        <span class="o">}</span>
    <span class="o">}</span>
<span class="o">}</span>
</code></pre></div></div>

<p>In one of our environments, this recently <strong>stopped working</strong>. What’s worse, is
that we still aren’t entirely sure why. We migrated the Jenkins workloads from
an older Kubernetes cluster to a newer one, and afterwards this “dind” approach
to building containers started throwing incredibly confusing network and
filesystem errors. Smart money is on some host kernel or filesystem
configuration issue which is causing the “dind” container, which must run
“privileged”, to function incorrectly. After an hour or two of debugging, I
said “forget this” (I may have used slightly different words) and started
looking at other options.</p>

<h2 id="kaniko">Kaniko</h2>

<p><a href="https://github.com/GoogleContainerTools/kaniko">Kaniko</a> is a curious tool from
Google which allows the building of containers on top of Kubernetes. By curious
I mean that it works fairly different from a “stock” <code class="language-plaintext highlighter-rouge">docker build</code> invocation
and required some tweaking on our end to get things working comfortably. That
said, our initial work is promising and we think we’re going to be switching
fully over to it.</p>

<p>The biggest oddity is the need for intermediate layers in the container build,
and the resultant image to be published to repository. My colleague
hypothesized that this was likely a pattern from Google Cloud Platform, where
local VM disks might not be as fast as the container registry affiliated with a
cluster. While there are local filesystem caching options we found them too
unreliable to be useful.</p>

<p>For our configuration of Kaniko, we riffed on the <em>Scripted</em> Pipeline examples
shared by my former colleagues <a href="https://go.cloudbees.com/docs/cloudbees-core/cloud-install-guide/kubernetes-using-kaniko/">at
CloudBees</a>,
but made some fairly significant modifications along the way. Most notably, we
decided to stand up an ephemeral Docker registry inside the Kaniko pod rather
than rely on an external registry for intermediate layers. The end product is
pushed to a well supported network-based registry, but the intermediate layers
are perfectly fine to run locally, as we have very fast disk I/O on our
Kubernetes nodes.</p>

<p>Kaniko’s invocation is much different, and the way it treats its build context
is also a little odd. In our testing we found that the <code class="language-plaintext highlighter-rouge">--cleanup</code> flag was not
enabled <em>by default</em> and successive calls to Kaniko would <strong>mash all</strong> the
files from different contexts on top of one another in some temp directory used
by Kaniko for builds, thereby leading to frustrating build failures. It should
also be noted that the Kaniko containers use Busybox for their shell, but it’s
on a fun non-standard path (<code class="language-plaintext highlighter-rouge">/busybox/sh</code>), so shell scripts expecting
<code class="language-plaintext highlighter-rouge">/bin/sh</code> or <code class="language-plaintext highlighter-rouge">/bin/bash</code> will definitely fail!</p>

<p>We use Declarative Pipeline very heavily and also utilize own custom JNLP agent
image in Jenkins (custom root certificates!), so the snippet below is should be
largely portable to your environment but may need some tweaks:</p>

<div class="language-groovy highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">pipeline</span> <span class="o">{</span>
    <span class="n">stages</span> <span class="o">{</span>
        <span class="n">stage</span><span class="o">(</span><span class="s1">'Buildo Roboto'</span><span class="o">)</span> <span class="o">{</span>
            <span class="n">agent</span> <span class="o">{</span> 
                <span class="n">kubernetes</span> <span class="o">{</span>
                    <span class="n">defaultContainer</span> <span class="s1">'kaniko'</span>
                    <span class="n">yamlFile</span> <span class="s1">'kaniko.yaml'</span>
                <span class="o">}</span>
            <span class="o">}</span>
            <span class="n">steps</span> <span class="o">{</span>
                <span class="cm">/*
                 * Since we're in a different pod than the rest of the
                 * stages, we'll need to grab our source tree since we don't
                 * have a shared workspace with the other pod(s)..
                 */</span>
                <span class="n">checkout</span> <span class="n">scm</span>
                <span class="n">sh</span> <span class="s1">'sh -c ./scripts/build-kaniko.sh'</span>
            <span class="o">}</span>
        <span class="o">}</span>
    <span class="o">}</span>
<span class="o">}</span>
</code></pre></div></div>

<p><strong>kaniko.yaml</strong></p>
<div class="language-yaml highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1"># This pod specification is intended to be used within the Jenkinsfile for</span>
<span class="c1"># building the Docker containers</span>
<span class="c1">#</span>
<span class="c1"># E.g. /kaniko/executor --context `pwd` --destination localhost:5000/roboto:latest --insecure-registry localhost:5000 --cleanup</span>
<span class="nn">---</span>
<span class="na">kind</span><span class="pi">:</span> <span class="s">Pod</span>
<span class="na">metadata</span><span class="pi">:</span>
  <span class="na">name</span><span class="pi">:</span> <span class="s">kaniko</span>
<span class="na">spec</span><span class="pi">:</span>
  <span class="na">containers</span><span class="pi">:</span>
  <span class="pi">-</span> <span class="na">name</span><span class="pi">:</span> <span class="s">jnlp</span>
    <span class="c1"># Overwriting the jnlp container's default "image" parameter, this will be</span>
    <span class="c1"># merged automatically with the Kubernetes plugin's built-in jnlp container</span>
    <span class="c1"># configuration, ensuring that the pod comes up and is accessible</span>
    <span class="na">image</span><span class="pi">:</span> <span class="s1">'</span><span class="s">our-awesome-registry/rtyler/jenkins-agent:latest'</span>
  <span class="pi">-</span> <span class="na">name</span><span class="pi">:</span> <span class="s">kaniko</span>
    <span class="na">image</span><span class="pi">:</span> <span class="s">gcr.io/kaniko-project/executor:debug</span>
    <span class="na">imagePullPolicy</span><span class="pi">:</span> <span class="s">Always</span>
    <span class="c1"># Command and args are important to set in this manner such that the</span>
    <span class="c1"># Jenkins Pipeline can send commands to be executed from the Jenkinsfile via</span>
    <span class="c1"># stdin (that's how it really works!)</span>
    <span class="na">command</span><span class="pi">:</span>
    <span class="pi">-</span> <span class="s">/busybox/sh</span>
    <span class="pi">-</span> <span class="s2">"</span><span class="s">-c"</span>
    <span class="na">args</span><span class="pi">:</span>
    <span class="pi">-</span> <span class="s">/busybox/cat</span>
    <span class="na">tty</span><span class="pi">:</span> <span class="no">true</span>
  <span class="c1">#  Kaniko requires a registry, so we're just bringing one online in the pod</span>
  <span class="c1">#  for the intermediate caching of layers</span>
  <span class="pi">-</span> <span class="na">name</span><span class="pi">:</span> <span class="s">registry</span>
    <span class="na">image</span><span class="pi">:</span> <span class="s1">'</span><span class="s">registry'</span>
    <span class="na">command</span><span class="pi">:</span>
    <span class="pi">-</span> <span class="s">/bin/registry</span>
    <span class="pi">-</span> <span class="s">serve</span>
    <span class="pi">-</span> <span class="s">/etc/docker/registry/config.yml</span>
</code></pre></div></div>

<p>Our experience with Kaniko thus far is that it has been slower, and less
verbose in some of its output than <code class="language-plaintext highlighter-rouge">docker build</code>. Fortunately though it’s been
quite reliable, and that’s the key factor here!</p>

<p>Hopefully with the snippets of code above you won’t need to spend nearly as
much time tinkering as my colleague and I did. But in the process of switching
over to Kaniko we needed to do a <em>lot</em> of interactive debugging in Jenkins, so
I was glad to have something like an <a href="/2017/08/07/jenkins-pipeline-shell.html">interactive
shell</a> in my bag of Jenkins Pipeline
tricks.</p>

<p>While I liked the “dind” solution, the Kaniko-based solution is just as
well. The future development for us is to hide some of this complexity with
<a href="https://jenkins.io/doc/book/pipeline/shared-libraries">shared libraries</a>, but
that’s a project for another day!</p>]]></content><author><name>R. Tyler Croy</name></author><category term="jenkins" /><category term="kubernetes" /><category term="kaniko" /><category term="scribd" /><summary type="html"><![CDATA[I have a love/hate relationship with containers. We have used containers for production services in the Jenkins project’s infrastructure for six or seven years, where they have been very useful. I run some desktop applications in containers. There are even a few Kubernetes clusters which show the tell-tale signs of my usage. Containers are great. Not a week goes by however when some oddity in containers, or the tools around them, throws a wrench into the gears and causes me great frustration. This week was one of those weeks: we suddenly had problems building our Docker containers in one of our Kubernetes environments.]]></summary></entry><entry><title type="html">Jenkins with agents on a separate Kubernetes cluster</title><link href="https://brokenco.de//2019/09/23/jenkins-kuberenetes-master-separation.html" rel="alternate" type="text/html" title="Jenkins with agents on a separate Kubernetes cluster" /><published>2019-09-23T00:00:00+00:00</published><updated>2019-09-23T00:00:00+00:00</updated><id>https://brokenco.de//2019/09/23/jenkins-kuberenetes-master-separation</id><content type="html" xml:base="https://brokenco.de//2019/09/23/jenkins-kuberenetes-master-separation.html"><![CDATA[<p>Running untrusted CI/CD workloads in Jenkins is perhaps my favorite security
discussion. Throwing <a href="/2019/02/14/untrusted-docker-workloads.html">Docker into the
mix</a> makes things even
interesting, and in some cases less secure. Today I implemented a pattern which
I have discussed with colleagues but hadn’t yet had the opportunity to try: a
multi-Kubernetes cluster for Jenkins. In short, running a Jenkins master in a
cluster which acts as the control pane for it and many other services, while
running all of its workloads in an entirely separate Kubernetes cluster. For
those who know the joy of managing Kubernetes this may seem like madness, but
it does offer a number of security benefits which I would like to outline.</p>

<p>The Jenkins master doesn’t particularly benefit from running in Kubernetes.
Its <a href="/2017/12/01/aks-storage-research.html">storage requirements and access
patterns</a> are orthogonal to the
preferred stateless applications which Kubernetes excels at supporting. The
Jenkins <em>agents</em> however are an ideal application for Kubernetes: stateless,
ephemeral, and elastic workloads which can benefit from spinning up in seconds
and running within containers.</p>

<p>In fact, there’s a reasonable argument to be made for <em>not</em> running Jenkins
masters in Kubernetes at all! Nonetheless I prefer to run Jenkins in Kubernetes
because of its administration and delivery benefits. The problems arise when
the master is run with the agents in the <em>same</em> cluster, which I discussed
previously <a href="/2019/02/14/untrusted-docker-workloads.html">here</a>, but in short:</p>

<ul>
  <li>Noisy-neighbor problems are abound: a pipeline which saturates CPU or network
I/O will adversely affect the master’s performance as well.</li>
  <li>Lack of isolation: the Jenkins master has all sorts of tasty credentials and
should any user workload take advantage of a hole in Kubernetes, or more
commonly, a misconfiguration allowing access to the Kubernetes API or Docker
socket, they will be able to trivially access the master’s filesystem.</li>
</ul>

<p>The model which I have now deployed is one where a control plane cluster, with
a different set of access grants for Vault, different monitoring, alerting, and
auditing, is configured to run the Jenkins master among a number of other
important internal tools. A second cluster, which is trusted with far less
responsibility than the control plane is made available to the Jenkins
<a href="https://plugins.jenkins.io/kubernetes">Kubernetes plugin</a>.</p>

<h3 id="configuring-jenkins">Configuring Jenkins</h3>

<p>In order for this arrangement to work a couple prerequisites need to be squared
away first:</p>

<ul>
  <li>The master requires a fixed JNLP port, e.g. 50000, which can be exposed
outside the control plane for agents to properly phone home.</li>
  <li>The <a href="https://github.com/jenkinsci/kubernetes-plugin/blob/master/src/main/kubernetes/service-account.yml">service account</a>
configuration recommended by the Kubernetes plugin needs to be applied to the
untrusted Kubernetes cluster.</li>
  <li>Ensure the Jenkins master has HTTP and JNLP properly exposed.</li>
  <li>Network connectivity must allow the control plane to access the API
controller on the untrusted Kubernetes cluster. The untrusted cluster must
also be able to access the Jenkins master via HTTP.</li>
</ul>

<p>With these in place, the actual configuration within Jenkins is quite simple!
Much of the documentation online assumes the master and agents are running in
the same cluster, so for this set up we must deviate a <em>bit</em> from what’s
commonly done in the “Configure System” view:</p>

<ul>
  <li>Add the untrusted Kubernetes API URL to the “Kubernetes URL” field</li>
  <li>Insert the untrusted cluster’s server certificate key under “Kubernetes
server certificate key” (really complex stuff here).</li>
  <li>Add a <strong>Secret Text</strong> credential with the untrusted cluster’s service
account’s access token. This you will then select from the dropdown in the
configuration as “Credentials.”</li>
  <li>Add the correct Jenkins URL to the Jenkins master on the control plane.</li>
</ul>

<p>With this configuration in place, the specified pod templates will start
provisioning in the untrusted cluster as soon as the configuration is saved;
neat! Adding configuration to the untrusted cluster like the <a href="https://docs.microsoft.com/en-us/azure/aks/virtual-kubelet">Virtual Kubelet in
Azure</a> can greatly
improve the performance and elasticity of the agent workloads too!</p>

<p>Having more than one Kubernetes cluster is something anybody running Kubernetes
should consider since it <a href="https://blog.jessfraz.com/post/secret-design-docs-multi-tenant-orchestrator/">wasn’t really designed for
multi-tenancy</a>.
Chances are, if you think Kubernetes is a solution for problems you have,
your organization is also large enough to have wildly different requirements
from your compute environment, thereby justifying multiple clusters as I am
using here.</p>

<p>Structuring our Jenkins environments in this way also makes it <em>much</em> easier to
run a single large untrusted compute cluster, while having multiple Jenkins
master instances in the control plane. Providing ourselves with better resource
utilization, isolation, and easier capacity planning.</p>

<p>I don’t necessarily recommend this approach for everybody, but once you’re
already invested in Kubernetes, what’s one more cluster in the mix? :)</p>]]></content><author><name>R. Tyler Croy</name></author><category term="jenkins" /><category term="kubernetes" /><summary type="html"><![CDATA[Running untrusted CI/CD workloads in Jenkins is perhaps my favorite security discussion. Throwing Docker into the mix makes things even interesting, and in some cases less secure. Today I implemented a pattern which I have discussed with colleagues but hadn’t yet had the opportunity to try: a multi-Kubernetes cluster for Jenkins. In short, running a Jenkins master in a cluster which acts as the control pane for it and many other services, while running all of its workloads in an entirely separate Kubernetes cluster. For those who know the joy of managing Kubernetes this may seem like madness, but it does offer a number of security benefits which I would like to outline.]]></summary></entry><entry><title type="html">The Configuration as Code plugin and “id must be specified” errors</title><link href="https://brokenco.de//2019/08/21/id-must-be-specified.html" rel="alternate" type="text/html" title="The Configuration as Code plugin and “id must be specified” errors" /><published>2019-08-21T00:00:00+00:00</published><updated>2019-08-21T00:00:00+00:00</updated><id>https://brokenco.de//2019/08/21/id-must-be-specified</id><content type="html" xml:base="https://brokenco.de//2019/08/21/id-must-be-specified.html"><![CDATA[<p>Yesterday we rebuilt and re-deployed one of the Jenkins containers we use at
work, and much to my chagrin the Jenkins environment no longer wanted to boot.
We use Jenkins on top of Kubernetes, integrated with <a href="https://www.vaultproject.io/">Hashicorp
Vault</a>,
configured with the <a href="https://github.com/jenkinsci/configuration-as-code-plugin">Configuration as Code
plugin</a> and the <a href="https://github.com/jenkinsci/job-dsl-plugin">Job
DSL plugin</a>. While I am pleased
with this stack of tools, it is <em>not</em> a “simple” set up.  It had been three
weeks since the last rebuild and redeploy, and the name of the game was: what
of the dozen changes that have happened in one of these tools over the last
three weeks was the culprit.</p>

<p>Any time Jenkins fails to boot, I immediately consult the daemon’s log. The
<a href="https://gist.github.com/rtyler/47233978223019cf5fa4714f8e8836d7">beginning of the
log</a> looked
mostly normal except for these sort of lines at the top:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>WARNING: Configuration import: Found unresolved variable GITLAB_TOKEN. Will default to empty string
</code></pre></div></div>

<p>Meanwhile at the <em>bottom</em> of the logs were the <a href="https://gist.github.com/rtyler/ecc54a59cdb2ed17f8d46db3746c41bd">actual
stacktraces</a>
which caused Jenkins to stop. The way I understood the stacktraces at the
bottom of the logs, was that they were relating to these warnings at the <em>top</em>
of the logs. The Job DSL script being used was referencing this credential
configured from the <code class="language-plaintext highlighter-rouge">GITLAB_TOKEN</code> variable.</p>

<p>My primitive monkey logic was: a warning that a secret variable is not present
must mean that Jenkins is not getting secrets from Vault, and therefore the
credential ID being referenced in the Job DSL script is empty causing a
problem.</p>

<p>Looking more seriously at Vault, my leading hypothesis was that we had recently
added secret strings which were tripping up the secret parsing in the Jenkins
Configuration as Code plugin. The plugin is what actually connects to Vault,
fetches secrets, and makes them available as variables for expansion in its
configuration YAML. My first step was to <a href="https://gist.github.com/rtyler/55bf0a912287094deb2e55589e537911">make the log level much more
granular</a> to
see if Jenkins and Vault were still communicating properly. Sifting through 6MB
of logs, I confirmed that communication with Vault was in tact.</p>

<p>The build of our Docker container defaults to take the latest plugins at
build time. Some might consider this risky, but I believe that it’s better to
risk upgrades, than to fall behind on Jenkins plugin versions which itself can
be a difficult hole to dig out of. I noticed in our build logs that the
Configuration as Code plugin upgraded from 1.24 to 1.27 between the two
built versions of the container. The <a href="https://github.com/jenkinsci/configuration-as-code-plugin/releases">release
notes</a> for
1.25 looked suspicious as there were secrets related changes, but mostly in the
context of the “Export” functionality that the plugin supports. Either way, I
tried using the old version of the container and that <em>still</em> didn’t seem to
work for some reason!</p>

<p>It <em>had</em> to be Vault, I concluded.</p>

<p>The next rock I looked under was whether the secrets were malformed in Vault.
With help from a member of our security team, we started spelunking around in
Vault and even tried deleting some secrets recently added. That didn’t appear
to be the issue either!</p>

<p>At this point in the afternoon, I was pretty annoyed. Nothing made sense. I did
a little bit of a mental reset and decided to bring the Vault configuration to
my local machine and started testing out with a purely ephemeral version of the
container, e.g. <code class="language-plaintext highlighter-rouge">docker run --rm -ti myjenkins</code>.</p>

<p>In my local environment, I was able to boot the old version of the container,
but not the new version of the container. I was also unable to boot a newer
version of the container with an explicitly pinned 1.24 version of the
configuration as code plugin. Mysteries abound! In this local testing what I
noticed was that I was still seeing these warnings:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>WARNING: Configuration import: Found unresolved variable GITLAB_TOKEN. Will default to empty string
</code></pre></div></div>

<p>Yet, the credentials would still show up properly in the instance. The
Configuration as Code plugin was warning about secrets but they still managed
to show up anyways. This smelled quite fishy to me, and I posited in the
<a href="https://gitter.im/jenkinsci/configuration-as-code-plugin">configuration-as-code-plugin Gitter
room</a> that there’s a
race condition related to the fetching of secrets from Vault and the
configuration that the plugin is trying to set. With this hypothesis in place,
I returned to the bottom of the log where the Job DSL plugin stacktrace was:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Caused by: javaposse.jobdsl.dsl.DslScriptException: (script, line 37) id must be specified
</code></pre></div></div>

<p>Between the old and new versions of the container, the Job DSL plugin went from
1.74 to 1.75. By pinning the Job DSL plugin back one version ended up resolving
the issue! Noticing and reading <strong><a href="https://github.com/jenkinsci/job-dsl-plugin/wiki/Migration#migrating-to-175">this migration note for 1.75 confirmed the
problem</a></strong>.</p>

<p>I had not been able to reproduce this in Kubernetes previously, due to the
persistent volume which was effectively caching exploded plugin directories
between restarts. In <code class="language-plaintext highlighter-rouge">/var/jenkins_home/plugins/</code> there are directories of
plugins which have been expanded from their <code class="language-plaintext highlighter-rouge">.jpi</code> files, and in cases of a
plugin downgrade in the container, this wasn’t getting updated. Good to know
for the future!</p>

<p><del>In essence, the Configuration as Code plugin fetches secrets from Vault in an
asynchronous manner but it appears not to wait for results to come back before
it triggers the Job DSL seed job. With the release of Job DSL 1.75, the
referencing of credentials IDs went from unchecked/lazy to checked/strict. The
fact that the seed job was running before the credentials actually <em>existed</em>
became a fatal error which didn’t previously exist.</del></p>

<p><strong>UPDATE</strong>: The maintainer of the Job DSL plugin, <a href="https://twitter.com/daspilker/status/1164198195112620033">Daniel
Spilker</a> pointed out
that I cannot read English properly. The breaking change between Job DSL 1.74
and 1.75 has nothing to do with Credentials or the Configuration as Code
plugin, and was a complete red herring. The <code class="language-plaintext highlighter-rouge">id</code> property must now be applied
for all Git/GitHub branch source configuration. Basically, there’s a breaking
API change in Job DSL between these two point releases which tripped us up
here.</p>

<hr />

<p>Over the past decade I have become intimately familiar with many different
failure scenarios in Jenkins, more so than any other piece of software. It’s
nice to know that there are still new things to explore in our relationship
together.</p>]]></content><author><name>R. Tyler Croy</name></author><category term="jenkins" /><category term="job-dsl" /><category term="casc" /><summary type="html"><![CDATA[Yesterday we rebuilt and re-deployed one of the Jenkins containers we use at work, and much to my chagrin the Jenkins environment no longer wanted to boot. We use Jenkins on top of Kubernetes, integrated with Hashicorp Vault, configured with the Configuration as Code plugin and the Job DSL plugin. While I am pleased with this stack of tools, it is not a “simple” set up. It had been three weeks since the last rebuild and redeploy, and the name of the game was: what of the dozen changes that have happened in one of these tools over the last three weeks was the culprit.]]></summary></entry><entry><title type="html">How Jenkins usage statistics work</title><link href="https://brokenco.de//2019/05/23/jenkins-usage-stats.html" rel="alternate" type="text/html" title="How Jenkins usage statistics work" /><published>2019-05-23T00:00:00+00:00</published><updated>2019-05-23T00:00:00+00:00</updated><id>https://brokenco.de//2019/05/23/jenkins-usage-stats</id><content type="html" xml:base="https://brokenco.de//2019/05/23/jenkins-usage-stats.html"><![CDATA[<p>For years the Jenkins project has published anonymous usage statistics to
<a href="http://stats.jenkins.io">stats.jenkins.io</a>.  Despite its warts, the system has
ultimately proven useful for determining which plugins are most frequently
installed, big coarse-grained changes in growth, and providing various
marketing departments with the validation they so desperately crave.  Like many
of the tucked away corners of the Jenkins project, being an infrastructure
maintainer affords me an understanding of how the system works, and sometimes
doesn’t. As I promised to the <a href="https://cd.foundation">CDF</a> Technical Oversight
Committee many weeks ago, in this post I will attempt to describe how this
system works.</p>

<p>Buckle up, it’s about to get messy.</p>

<p>The party starts in Jenkins core, with
<a href="https://github.com/jenkinsci/jenkins/blob/master/core/src/main/java/hudson/model/UsageStatistics.java">UsageStatistics.java</a>
which is responsible for collecting and sending statistics, assuming the
administrator has not opted out. This data includes items like what the current
installed Jenkins core version is, how many executors have been configured, the
plugins installed, and a few other things. This information we don’t consider
anonymized by default, and take efforts to encrypt the data before it is sent
to a backend server.  When this was first developed, daemons like Jenkins were
not expected to contact outside services for any reason and as such it was much
more common for corporate firewalls to block outgoing traffic from Jenkins
instances. The clever workaround put into place was to generate the usage
statistics payload, and then to periodically add it to a user’s web page. The
presumption being that while the server might not be able to access
<code class="language-plaintext highlighter-rouge">jenkins-ci.org</code>, it was unlikely that a user’s web browser would restrict the
HTTP request. For reasons that escape me, this was all done via an HTTP <code class="language-plaintext highlighter-rouge">GET</code>
request, which also means the encrypted statistics payload must be base-64
encoded in order to pass properly in the query string of the request.</p>

<p>As an aside, this “make the user’s browser do the work” pattern was first
developed for the Update Center which distributes Jenkins plugins to users. We
found early on that Jenkins instances would not be able to update due to
overzealous firewalls. And so for many years, the Jenkins administrator’s
browser session would download the <code class="language-plaintext highlighter-rouge">update-center.json</code> into their browser, and
then POST it back to Jenkins. Now Jenkins defaults to hitting the
Update Center directly, which is good because that <code class="language-plaintext highlighter-rouge">update-center.json</code> has
blossomed to over 1MB in size.</p>

<p>Where were we again?</p>

<p>Oh right, encrypting statistics, base-64 encoding them, and stuffing them into
a web page for an HTTP GET request to send them along to the backend server.</p>

<p>Much of Jenkins was developed in the era before BIG DATA was commonplace.
We don’t use some sort of high performance data collector to receive all
of this statistics information, instead we use tried-and true Apache. “Huh, so
there’s a service being reverse proxied by Apache?” you might be thinking. No.
We use Apache. The HTTP GET requests flow into Apache, which logs the HTTP GET
request to its access logs whose query string contains the base-64 encoded and
encrypted payload. Ta-da! Data collected.</p>

<p>At this point we have access logs sitting on a server somewhere with usage
statistics, which have been encrypted, and unless your big data toolbox is only
<code class="language-plaintext highlighter-rouge">grep</code>, they’re largely unusable at this point.</p>

<p>On some interval, some machine somewhere in Kohsuke’s basement downloads these
access logs and runs
<a href="https://github.com/jenkins-infra/usage-log-decrypter">usage-log-decrypter</a> on
them. This process will decrypt the data, fuzz custom plugin names and a number
of other values to suitably anonymize the data, before uploading those logs
back to another Jenkins project server. Unfortunately usage statistics
processing is one of those community processes which still has a very thorny
single-point-of-failure sitting in Kohsuke’s basement, but it’s not important
enough for anybody to spend much time working on it.</p>

<p>The journey for these data points isn’t over yet however!</p>

<p>The data processing which turns anonymized usage logs into blue SVGs and CSV
files was originally developed for funsies by a contributor who wanted to play with
the data some weekend many years ago. Like lots of other things in open source
projects, these weekend hobby projects have a tendency to survive despite all
odds. That code has evolved in the
<a href="https://github.com/jenkins-infra/infra-statistics">infra-statistics</a>
repository. On a monthly basis, the scripting in that repo will load the
anonymized JSON usage statistics into a local MongoDB data store, then run a
bunch of different queries against it in order to produce the files for
<a href="https://stats.jenkins.io">stats.jenkins.io</a> which are then committed to the
<code class="language-plaintext highlighter-rouge">gh-pages</code> branch and pushed, serving the site’s static content via GitHub
Pages. As you might guess, loading bunches of data into an in-memory data store
has its limitations, namely with <em>the memory</em>. Last year, I believe, we
exceeded the amount of memory available for the Jenkins agents which
traditionally ran the monthly job. In the meantime,
<a href="https://github.com/abayer">Andrew</a> has been running the statistics processing
manually on a local workstation.</p>

<p>To recap, usage statistics from every Jenkins instance which does not opt-out,
are generated in a JSON object, which is then encrypted, then base-64 encoded,
it is thereafter smuggled along an HTTP GET request to an Apache server which
logs the request to the access log, from which it is downloaded, fuzzed,
reconstituted and uploaded back to a Jenkins server, then on a monthly cadence
it is downloaded, loaded into MongoDB, queried, and then finally formatted into
various CSV, JSON, and SVG files which are uploaded to GitHub Pages.</p>

<hr />

<p>Setting aside the obviously degraded state this aging system is currently in,
the right fix involves tearing the <em>entire</em> thing down.</p>

<p>I don’t think a new system is terribly difficult to design and build, but
similar to my work with on <a href="/2019/05/06/whats-uplink.html">Uplink</a>, it requires
Jenkins core and backend service changes to be made in concert, something we’re
not very adept at doing in the project.</p>

<p>The original context in which I was asked about this system was as a reference
for the common problem affecting the other projects within the CDF: <strong>how do
we measure success and adoption</strong>.</p>

<p>I think this is a great problem to solve, and worth serious investment. I have
many thoughts on how to revisit the topic with what we now know from our
experiences in the Jenkins project. A better approach which delivers usable
data more rapidly and with greater focus on user privacy, but that’s a topic
for another day, and perhaps another blog post.</p>]]></content><author><name>R. Tyler Croy</name></author><category term="jenkins" /><category term="cdf" /><summary type="html"><![CDATA[For years the Jenkins project has published anonymous usage statistics to stats.jenkins.io. Despite its warts, the system has ultimately proven useful for determining which plugins are most frequently installed, big coarse-grained changes in growth, and providing various marketing departments with the validation they so desperately crave. Like many of the tucked away corners of the Jenkins project, being an infrastructure maintainer affords me an understanding of how the system works, and sometimes doesn’t. As I promised to the CDF Technical Oversight Committee many weeks ago, in this post I will attempt to describe how this system works.]]></summary></entry><entry><title type="html">What’s Uplink</title><link href="https://brokenco.de//2019/05/06/whats-uplink.html" rel="alternate" type="text/html" title="What’s Uplink" /><published>2019-05-06T00:00:00+00:00</published><updated>2019-05-06T00:00:00+00:00</updated><id>https://brokenco.de//2019/05/06/whats-uplink</id><content type="html" xml:base="https://brokenco.de//2019/05/06/whats-uplink.html"><![CDATA[<p>Making changes safely to an application like <a href="https://jenkins.io">Jenkins</a> is
<em>incredibly</em> tricky. Jenkins is distributed to hundreds of thousands of
independently owned and operated servers and is used in a myriad of ways.
Our changes with the best intentions, can still result in confounding bugs and errors
for users with different configurations, or different combinations of plugins.  Over on
the <a href="https://jenkins.io/">Jenkins project</a> blog, Daniel wrote about the <a href="https://jenkins.io/blog/2019/05/05/telemetry-success">first
use of “telemetry” by Jenkins
core</a>, a project on which
we collaborated. I ended up building the backend service for receiving this
telemetry, <a href="https://github.com/jenkins-infra/uplink">Uplink</a>, and I hope it
paves the way for making smarter changes across Jenkins core in the future.</p>

<p>Many developers within the Jenkins community know about the <a href="http://github.com/jenkinsci/jep">Jenkins Enhancement
Proposal</a>, but few will know each proposal by
number <em>except</em> for <a href="https://jenkins.io/blog/2018/01/13/jep-200/">JEP-200</a>.
While JEP-200 described an important security design improvement, its rollout
to the Jenkins userbase left a large number of problems in its wake. We simply
didn’t know enough about how plugins were using some features and how they
might break.</p>

<p>The <code class="language-plaintext highlighter-rouge">SECURITY</code> ticket which inspired this telemetry-oriented approach was
another one of those tickets everybody seems to know only by its number. The
problem was, as Daniel describes in his blog post:</p>

<blockquote>
  <p><em>Jenkins uses the Stapler web framework for HTTP request handling. Stapler’s
basic premise is that it uses reflective access to code elements matching its
naming conventions. [..] As these naming conventions closely match common code
patterns in Java, accessing crafted URLs could invoke methods never intended to
be invoked this way. [..] We identified a number of URLs that could be abused
to access otherwise inaccessible jobs, or even invoke internal methods in the
web application server to invalidate all sessions.</em></p>
</blockquote>

<p>Some ideas for fixing the problem had been discussed over many months, but we
kept getting stuck on one big detail: how can we possibly make a major change
without causing a major breakage, like we had inadvertently done with JEP-200.
The exact chronology I do not recall, but I believe that I eventually
convinced Daniel that we could cheaply and easily stand up a telemetry service.
One which would allow Jenkins instances to give the security team the answers
they needed to move forward with a fix. In doing so, I volunteered to write and
deploy the backend service (<a href="https://github.com/jenkins-infra/uplink">Uplink</a>)
which would receive the data.</p>

<p>The entirety of the telemetry system is described in
<a href="https://github.com/jenkinsci/jep/blob/master/jep/214/README.adoc">JEP-214</a>,
but I want to highlight some specific characteristics of the system.</p>

<p><strong>Privacy</strong> is an important trait to both Daniel and I, and we designed this
telemetry system with that in mind. In Jenkins core, telemetry is captured and
sent as part of “trials.” These trials must have a pre-defined start and end
date, which ensures that the Jenkins project <strong>stops</strong> collecting data after a
certain point in time. The trials are supposed to answer questions which drive
decision making, not provide behavioral or user-analytics. Instances which
opt-out of reporting anonymous usage statistics, naturally will not report
telemetry either.</p>

<p>Inside of the payloads sent to Uplink, we send an instance ID. The instance ID
allows us to de-duplicate, or observe how data changes within a given trial.
For additional privacy, we enhanced this system to generate a <strong>different</strong>
instance ID for each trial, preventing the ability to correlate behavior of a
single instance across different trials. I will also note that this enhancement
was added after telemetry had been initially released, but we went back after
the fact and transformed the instance IDs already in the database to apply our
privacy principles evenly.</p>

<p>On the server-side we have designed Uplink to make it easy to <em>delete</em> data.
None our trials are old enough yet to warrant it, but since instances stop
sending data at a certain point, we can truncate tables once we’re finished
implementing the fix which inspired the trial. Uplink also restricts access to
telemetry data to a very select group of people. Since this data could be
valuable for a developer working to improve Jenkins, Uplink allows for
trial-based access control. Should a developer create a new
<code class="language-plaintext highlighter-rouge">scripted-noncps-pipeline-usage</code> trial, we would be able to grant that
developer access to <em>only</em> those events in the Uplink dashboard.</p>

<hr />

<p>As an aside, I should mention that Uplink is the second <a href="https://feathersjs.com">Feathers
JS</a> service which I have developed. The backend for
<a href="https://github.com/jenkins-infra/evergreen">Jenkins Evergreen</a> being the
first. The framework has been enjoyable to use, and I would recommend it for
building simple little Node-based microservices.</p>

<hr />

<p>For just about any piece of software, without information about how the
software runs in a real user’s environment, it can be tricky to deliver changes
safely. Many people are familiar with this requirement for web applications
they own and control, but those distributing software don’t tend to apply the
same principles of monitoring and continuous feedback. Adding feedback
mechanisms to software running on a user’s machine can be done, but must be
done in a way that strives to protect their privacy and allows them to disable
it entirely.</p>

<p>With the Jenkins Telemetry system, and the Uplink backend service, I am
particularly proud of how we have balanced these concerns while enabling
developers to build a better Jenkins!</p>]]></content><author><name>R. Tyler Croy</name></author><category term="jenkins" /><summary type="html"><![CDATA[Making changes safely to an application like Jenkins is incredibly tricky. Jenkins is distributed to hundreds of thousands of independently owned and operated servers and is used in a myriad of ways. Our changes with the best intentions, can still result in confounding bugs and errors for users with different configurations, or different combinations of plugins. Over on the Jenkins project blog, Daniel wrote about the first use of “telemetry” by Jenkins core, a project on which we collaborated. I ended up building the backend service for receiving this telemetry, Uplink, and I hope it paves the way for making smarter changes across Jenkins core in the future.]]></summary></entry><entry><title type="html">Thoughts about a secure enclave for Jenkins Pipeline</title><link href="https://brokenco.de//2019/04/30/pipeline-secure-enclave.html" rel="alternate" type="text/html" title="Thoughts about a secure enclave for Jenkins Pipeline" /><published>2019-04-30T00:00:00+00:00</published><updated>2019-04-30T00:00:00+00:00</updated><id>https://brokenco.de//2019/04/30/pipeline-secure-enclave</id><content type="html" xml:base="https://brokenco.de//2019/04/30/pipeline-secure-enclave.html"><![CDATA[<p>Continuous integration and continuous delivery (CI/CD) projects might just be
one of the hardest to lock down and secure. As system designers and
implementors we must enable developers to automate their builds, tests, and
deployments. And yet, in doing so, we also give those same developers the
ability to bypass many of the boundaries we may have set up to secure our
environments. If you give me the ability to automate my deployment with a
script, I can think of a number of ways in which that ability can lead to
information disclosure or other types of breaches. <a href="https://jenkins.io/doc/book/pipeline">Jenkins
Pipeline</a> is filled with any number of
problematic examples here the same feature can be looked at as <em>empowering</em> or
as <em>compromising</em>. I believe the immense flexibility of Jenkins Pipeline also gives us
a path to provide automation which is inherently more secure than some
competitors. In this post, I’ll outline one such idea: a pipeline secure
enclave.</p>

<p>I have spent a lot of time thinking about how to properly secure CI/CD
workloads, and it’s genuinely a tough problem, as you may have noticed from
some of my previously blog posts:</p>

<ul>
  <li><a href="/2019/04/15/trust-and-jenkins.html">Jenkins should not be the only line of defense</a></li>
  <li><a href="/2019/02/22/its-not-credentials-stealing.html">It’s not stealing when you’re giving them away</a></li>
  <li><a href="/2019/02/14/untrusted-docker-workloads.html">Securely running Docker workloads in your CI/CD
environment</a></li>
  <li><a href="/2018/01/05/jenkins-policy-enforcement.html">Enforcing administrative policy in Jenkins, the hard
way</a></li>
  <li><a href="/2017/08/03/donut-disable-groovy-sandbox.html">Do not disable the Groovy
Sandbox</a></li>
</ul>

<p>Many systems typically expose credentials to scripts via environment variables.
Many tools, Jenkins included make a good effort to mask these credentials
should some developer accidentally
or maliciously attempt ot log them to the console output. As I <a href="/2019/02/22/its-not-credentials-stealing.html">have shown
before</a>, this simply does not
adequately protect credentials. It’s possible to leak credentials by: piping
them through some encoding before printing, archiving them as artifacts,
sending them to a remote service, along with numerous slight variations on
those three approaches. So long as a credential is exposed to code editable by
developers, it is trivial to leak.</p>

<p>Unlike some of its competitors, I believe Jenkins Pipeline has the tooling
necessary to provide a secure approach to utilizing credentials in the CI/CD
process. My “secure enclave” proposal revolves around a key feature: <a href="https://jenkins.io/doc/book/pipeline/shared-libraries">Shared
Libraries</a>. With shared
libraries, administrators can load common snippets of pipeline code into the
master, for easy re-use within multiple projects. To learn more about some of
the cool things you can do with shared libraries, I recommend <a href="https://www.youtube.com/watch?v=lzzx59kLW9w&amp;list=PLvBBnHmZuNQLqgKDFmGnUClw68qsQ9Hq5&amp;index=46">Alvin Huang’s presentation from Jenkins World 2017</a>.</p>

<p>A secure enclave for Jenkins Pipeline would rest upon the foundation provided
by shared libraries, but require additional implementation to properly secure
credentials:</p>

<ul>
  <li>
    <p>An administrator would need to be able to bind credentials <strong>solely</strong> to the
shared library. Right now there are system-level, and folder-level
credentials in Jenkins. For system-level credentials, there is nothing which
prevents my <code class="language-plaintext highlighter-rouge">Jenkinsfile</code> from utilizing a credential so long as I know the ID
before hand.</p>

    <p>By allowing the credential to be bound solely to the shared library, then the
credential would not be accessible to pipelines developed and used elsewhere in
the master.</p>
  </li>
  <li>
    <p>Utilizing the credential within the shared library would need to be done in a
manner which does <em>not</em> allow arbitrary user code to be utilized. After all,
if the shared library provides me a function to pass in code, which is then
executed with access to the credentials, then we would have gained nothing.</p>

    <p>Invocations into the “secure enclave” methods would need to reject <code class="language-plaintext highlighter-rouge">Closure</code>
types from being passed, and likely need to tag and track <code class="language-plaintext highlighter-rouge">String</code>/<code class="language-plaintext highlighter-rouge">GString</code>
types to ensure those aren’t inadvertently passed to the <code class="language-plaintext highlighter-rouge">sh</code> step or
interpolated into other strings. Suggesting this is a little out of my
comfort zone, since I don’t fully understand how the <code class="language-plaintext highlighter-rouge">workflow-cps</code> engine
underneath functions. I feel fairly certain that special-case tracking and handling of a
<code class="language-plaintext highlighter-rouge">CredentialsString</code> would <em>not</em> be the gnarliest bit of object-hacking going on
in CPS.</p>
  </li>
  <li>
    <p>To further avoid inadvertent disclosure, Pipelines which attempt to use a
secure enclave would need to use the Groovy sandbox, and should probably not
be allowed any <code class="language-plaintext highlighter-rouge">@NonCPS</code> methods as well. Furthermore, a secure enclave
must not be editable on Replay of a Pipeline except by a Jenkins
administrator.</p>
  </li>
</ul>

<p>I believe this approach would provide a rigid set of constraints that would
provide increased security for the use of secrets in a Jenkins environment,
while still providing flexibility to developers and administrators.</p>

<p>That said, there is still a potential “escape” if an administrator is enabling
code in this secure enclave simply access the credentials and immediately
passes them into code defined by the repository:</p>

<div class="language-groovy highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kt">void</span> <span class="nf">deployit</span><span class="o">()</span> <span class="o">{</span>
    <span class="n">checkout</span> <span class="n">scm</span>

    <span class="nf">withCredentialsthCredentials</span><span class="o">([</span><span class="n">string</span><span class="o">(</span><span class="nl">credentialsId:</span> <span class="s1">'aws-secret'</span><span class="o">,</span> <span class="nl">variable:</span> <span class="s1">'AWS_SECRET'</span><span class="o">)])</span> <span class="o">{</span>
        <span class="n">sh</span> <span class="s1">'./deploy.sh'</span>
    <span class="o">}</span>
<span class="o">}</span>
</code></pre></div></div>

<p>When thinking about this aspect of the problem, I was considering the potential
to lock down a workspace, or only allow code in the secure enclave to interact
with stashed or archived artifacts. These approaches still suffer from the same
type of circumventions, I am not convinced that the problem is 100% solvable
while still allowing developers to own the code running in their CI/CD
pipelines.</p>

<p>The secure enclave approach is just one potential improvement to the security of
Jenkins Pipeline. Perhaps a bit complex but I believe it would provide a more
comprehensive layer of security atop Jenkins Pipeline.</p>

<p>Another, far simpler, approach would allow the binding of credentials to
a Pipeline and some source control criteria. In my continuously delivered world, the
<code class="language-plaintext highlighter-rouge">master</code> branch indicates a pre-existing level of trust and validation. Code in
<code class="language-plaintext highlighter-rouge">master</code> often is trusted enough to be deployed to a staging or test
environment. Relying on that pre-existing system of trust and only binding a
credential, thereby making it available to the <code class="language-plaintext highlighter-rouge">Jenkinsfile</code> in the <code class="language-plaintext highlighter-rouge">master</code>
branch, would be a simple improvement to the security of Jenkins Pipelines.</p>

<p>There is certainly still be potential for disclosures, but if I am already
putting systems of trust around that merge to <code class="language-plaintext highlighter-rouge">master</code>, I likely have bigger
problems if untrusted/unvalidated code is finding its way to the master branch.</p>

<hr />

<p>Any way we look at it, I think Jenkins Pipelines and their treatment of
credentials are quite lacking given the scope and severity of inadvertent
disclosures which have happened over the past couple years. Additionally, none of the
approaches I suggest above would be effective so long as the current system for
adding global credentials and accessing them in pipelines are the “default”
flow. Jenkins must make it more difficult to add and use credentials in
insecure ways.</p>]]></content><author><name>R. Tyler Croy</name></author><category term="jenkins" /><category term="pipeline" /><category term="opinion" /><category term="otto" /><summary type="html"><![CDATA[Continuous integration and continuous delivery (CI/CD) projects might just be one of the hardest to lock down and secure. As system designers and implementors we must enable developers to automate their builds, tests, and deployments. And yet, in doing so, we also give those same developers the ability to bypass many of the boundaries we may have set up to secure our environments. If you give me the ability to automate my deployment with a script, I can think of a number of ways in which that ability can lead to information disclosure or other types of breaches. Jenkins Pipeline is filled with any number of problematic examples here the same feature can be looked at as empowering or as compromising. I believe the immense flexibility of Jenkins Pipeline also gives us a path to provide automation which is inherently more secure than some competitors. In this post, I’ll outline one such idea: a pipeline secure enclave.]]></summary></entry><entry><title type="html">Minimum requirements to participate in a project</title><link href="https://brokenco.de//2019/04/24/minimum-requirements.html" rel="alternate" type="text/html" title="Minimum requirements to participate in a project" /><published>2019-04-24T00:00:00+00:00</published><updated>2019-04-24T00:00:00+00:00</updated><id>https://brokenco.de//2019/04/24/minimum-requirements</id><content type="html" xml:base="https://brokenco.de//2019/04/24/minimum-requirements.html"><![CDATA[<p>When waiting for containers to build, or dependencies to download, my mind
tends to wander. Yesterday it wandered to the plight of new contributors to
modern free and open source projects; how much they must do before even
attempting to collaborate! I started a <a href="https://twitter.com/agentdero/status/1120713097986002944">Twitter
poll</a>, asking:</p>

<blockquote>
  <p><em>In order to participate in my open source project, you must have at
minimum:</em></p>

  <ul>
    <li><em>GitHub account</em></li>
    <li><em>Google account</em></li>
    <li><em>Slack account</em></li>
    <li><em>signed CLA faxed to legal</em></li>
  </ul>
</blockquote>

<p>The results were overwhelmingly in favor of requiring, at minimum, a
<a href="https://github.com">GitHub</a> account. This was the result I expected and
certainly matches the anecdotal experiences I have had in recent years.</p>

<p>Unfortunately Twitter polls doesn’t allow multiple selections, as the reality
for most people is that they need <em>all</em> of those, as <a href="https://twitter.com/felis_rex/status/1120735653422075910">Felix
Frank</a> alluded to in
his response. When I think of the <a href="https://jenkins.io">Jenkins</a> project in
particular, the “registration” process for new contributors might typically
include:</p>

<ul>
  <li>A GitHub account.</li>
  <li>An LDAP account to access Jira, Confluence, and Jenkins-on-Jenkins.</li>
  <li>Connecting to IRC over Freenode, or a <a href="https://gitter.im">Gitter</a> channel,
depending on their focus area.</li>
  <li>Subscription to a mailing list operated by Google Groups.</li>
  <li>A Google account, if they want to participate in Hangouts or comment on
Google Docs for various design documents.</li>
</ul>

<p>As we have discussed newer services to incorporate into the community, I have
grown weary over the number of logins we would expect each contributor to
maintain.</p>

<p>I do not find myself reminiscing about the “good old days” of open source
software, when things were more oriented around Bugzilla, CVS/Subversion, mailing
lists, and IRC. There too we had account sprawl, it was perhaps a bit more
non-obvious.</p>

<p>For the Jenkins project, the ideal world would mean that everything linked to
our project’s LDAP infrastructure. With services like GitHub, That is obviously
not possible, so the next best thing would be to use GitHub as the source of
identity for all our other development services. Yes this couples us more
closely with GitHub, but at least then we would stop pretending we’re not
already intricately bound with GitHub as a service.</p>

<p>As many projects approach the summer, and Google Summer of Code kicks off, I
encourage you to consider the number of accounts, repositories, groups, and
other information a student or new-contributor must have in order to <em>start</em>
adding to the community.</p>

<p>Our goal as stewards of such projects, should be to push that number towards
zero.</p>]]></content><author><name>R. Tyler Croy</name></author><category term="opinion" /><category term="opensource" /><category term="jenkins" /><summary type="html"><![CDATA[When waiting for containers to build, or dependencies to download, my mind tends to wander. Yesterday it wandered to the plight of new contributors to modern free and open source projects; how much they must do before even attempting to collaborate! I started a Twitter poll, asking:]]></summary></entry></feed>