Skip to content

Make things safe for running untrusted code #366

Closed

Description

@vito

(This issue's a WIP; just want to log this somewhere.)

I'd like to document Concourse's usage in running untrusted code, e.g. via pull requests. There's a pretty neat Pull Request resource already, but I can't in good conscience recommend using it until we have answers for the following attack vectors (some of which we already do).

In no particular order:

  1. DOS the host machine, forcing it to reboot (e.g. echo b > /proc/sysrq-trigger).
  2. Consume crazy amounts of memory/disk/bandwidth/etc. for extended periods of time.
  3. Reach arbitrary sensitive information within the worker's private or local network.
  4. Reach sensitive data on the worker's disk.
  5. Access pipeline credentials.
  6. Escalate task capabilities beyond normal.
  7. Affect (by killing) other processes running on the worker.

And here's how Concourse currently fares:

  1. OK. This should be safe as long as the containers don't run privileged. Of course, barring any kernel bugs or CVEs come out. We're talking fundamentals here.
  2. Not OK, but maybe not critical. We currently don't apply any memory, disk, or bandwidth limits on any containers. I don't want to force people to think about it, and having even optional configuration for this is dangerous (people will just forget to set it). I'm not sure if people expect this; maybe we should investigate what kind of limits Travis enforces?
  3. CRITICAL. By default, containers have unlimited access to the host machine's private network. Each worker currently binds on their external IP via TCP, so if the attacker can guess your worker IPs, they can reach your Garden servers and do bad things. This is fixable by setting network restrictions on the worker (--allowNetworks, --denyNetworks flags), but it may be a better idea to just have auth in front of Garden.
  4. OK, again barring CVEs. This one's pretty basic and is part of the point of running everything in containers.
  5. OK, as long as resources don't leak their credentials or something.
  6. OK; privileged lives in the pipeline config, not the task config, for this very reason.
  7. OK aside from points 3 (kill containers via Garden API) and 2 (OOM/other resources). The rest is basic containerization (PID namespaces).

Any others?

Activity

  1. concourse-bot commented on Apr 11, 2016

    @concourse-bot

    Hi there!

    We use Pivotal Tracker to provide visibility into what our team is working on. A story for this issue has been automatically created.

    The current status is as follows:

    • #117354659 Make things safe for running untrusted code

    This comment, as well as the labels on the issue, will be automatically updated as the status in Tracker changes.

  2. added a commit that references this issue on Aug 17, 2016
  3. stela commented on Jun 6, 2018

    @stela

    @vito
    5. is NOT OK, some resources do leak credentials, it's very easy to dump all your team's credentials, e.g. for deployment to production or git, even if the credentials are stored on CredHub or Vault. So far I found two paths to achieve this.

    A. If a developer has access to Concourse, the developer can set a new pipeline like:

    jobs:
    - name: show-animal-names
      plan:
      - task: show-animal-names
        config:
          platform: linux
          image_resource:
            type: docker-image
            source:
              repository: busybox
          params:
            TOPSECRET: "((production-deploy-password))"
          run:
            path: env
    

    B. If a developer can commit a "child" build.yml pipeline to version control and have Concourse execute it:
    main-pipeline.yaml

    resources:
    - name: mysrc
      type: git
      source:
        uri: [email protected]:me/mysrc.git
        branch: master
        private_key: ((github-private-key))
    
    jobs:
    - name: build-job
      public: false
      plan:
      - get: mysrc
      - task: tests
        file: mysrc/build.yml
    

    build.yml:

    platform: linux
    image_resource:
      type: docker-image
      source:
        repository: 'busybox'
    inputs:
    - name: mysrc
    run:
      path: env
    params:
      TOPSECRET: ((production-deploy-password))
    

    This is a shame, as Concourse is so close to getting this right, running resource types like git and cf out-of-reach from the main source code build, and only exposing explicitly passed ((variables)).

    B could be resolved by disabling variable-expansion in child-build.yml files, either completely or by flagging "developer-safe" variables in the main-pipeline.

    A could be resolved by either having fine-grained authorization of whom is permitted to execute set-pipeline, or better, I believe, by only permitting variable-expansion for trusted non-leaky resource types like git (I think?) but disable it for developer-controlled types like docker-image. However even deployment-resources like e.g. cf (Cloud Foundry) could be sensitive if the developer reroutes logins to a developer-controlled URL, the raw original password is sent (i.e. e.g. PAKE is not used).

  4. vito commented on Jun 6, 2018

    @vito
    ContributorAuthor

    @stela This issue is primarily concerned with "B". You bring up a good point. We should maybe just disallow variable expansion, or only allow it during fly execute. It'll make some people sad since they use it for image_resource credentials. But security comes first.

    I think RBAC is the solution to "A" - I really don't want to get into preferential treatment of resource types. There's really nothing about git that should make it any safer than docker-image, especially in light of CVEs. If someone can "set-pipeline" that's pretty much the keys to the kingdom. We're working on RBAC so you can control who can and can't - see #1317 and its precursor issue, #1888 (along with the epic/users label in general).

  5. stela commented on Jun 6, 2018

    @stela

    @vito thanks, disallowing variable expansion would probably be enough to make it secure against arbitrary developer commits. What you could get away with though for image_resource credentials and such, would be to somehow set those credentials declaratively by naming convention, e.g. if there's a vault/credhub key named teamname/pipelinename/docker_image/docker-registry-hostname/password or similar, it would automatically be assigned as a docker password value to matching docker-image resources?
    Or allow defining named docker repositories in the main pipeline.yml and then only allow the build.yml to refer to them and provide repository and tag values?

  6. vito commented on Jun 6, 2018

    @vito
    ContributorAuthor

    @stela I like the conventional paths approach but it might be a bit constraining; we've already received feedback from users that want to be able to break from Concourse's enforced convention and use their own paths and fine-grained Vault permissions/etc.

    One thing people can do without any task interpolation is use a pipeline-provided resource:

    resources:
    - name: golang
      type: docker-image
      source:
        repository: my-hub-account/my-image
        username: ((my-name))
        password: ((my-password))
    
    jobs:
    - name: unit
      plan:
      - get: my-repo
      - get: golang
      - task: my-repo/ci/unit.yml
        image: golang

    ...which people could do forever, but they seemed dissatisfied. Hmm.

  7. dstufft commented on Jul 5, 2018

    @dstufft

    If a deployment is only concerned about people committing things (particularly in untrusted pull requests), then "B" above is the only case we care about right?

  8. vito commented on Jul 5, 2018

    @vito
    ContributorAuthor
  9. dstufft commented on Jul 5, 2018

    @dstufft

    Is there currently any way to work around it? I've been poking at Concourse again, and I think maybe if the pipeline doesn't use any child tasks and stores all tasks in the pipeline itself it should be ok?

  10. vito commented on Jul 26, 2018

    @vito
    ContributorAuthor

    @dstufft (sorry for the delay) - yeah, as long as your pipeline doesn't load tasks from untrusted repositories (PRed repos) you should be safe. You could either inline them with config: or take them from some other repo that only you control.

  11. willmurphyscode commented on Apr 18, 2019

    @willmurphyscode

    @vito One mitigation I was planning to try was having the pipeline use a regular git resource pointed at master for pipeline code, and a GitHub PR resource only for application and test code. For example, something like:

    resource_types:
    - name: pull-request
      type: docker-image
      source:
        repository: teliaoss/github-pr-resource
    
    resources:
    - name: pr
      type: pull-request
      check_every: 1m
    - name: master
      type: git
      source:
        branch: master

    Then all the task configs are read off files like file: master/ci/tasks/units.yml for example. Does that seem like an adequate mitigation? That way, if a PR does change a task config file, the pipeline would continue to use master's version of that file.

    yeah, as long as your pipeline doesn't load tasks from untrusted repositories (PRed repos) you should be safe

    This fix really separates trusted from untrusted code by branch, not be repository, so I wanted to double check, but they seem equivalent to me.

  12. vito commented on May 14, 2019

    @vito
    ContributorAuthor

    @willmurphyscode 🐢 Yep, that seems sensible!

  13. added a commit that references this issue on May 24, 2019
  14. stale commented on Jul 16, 2019

    @stale

    Beep boop! This issue has been idle for long enough that it's time to check
    in and see if it's still important.

    If it is, what is blocking it? Would anyone be interested in submitting a
    PR
    or
    continuing the discussion to help move things forward?

    If no activity is observed within the next week, this issue will be
    exterminated closed, in accordance with our stale issue
    process
    .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions