Giter Club home page Giter Club logo

cap-sys-nice-docker's Introduction

cap-sys-nice-docker

Small docker image to experiment with CAP_SYS_NICE in Docker.

The entry point inspects /proc/1/status for Cap*: entries and then executes a small C program that tries to call sched_setscheduler() to set the SCHED_FIFO "real-time" scheduling policy.

A x86-64 image is published to docker hub. To build locally:

$ docker build --tag fredrikfornwall/cap-sys-nice-docker:0.1 .

Run using docker directly:

$ docker run fredrikfornwall/cap-sys-nice-docker:0.1
Inspecting /proc/1/status
CapInh:	0000000000000000
CapPrm:	00000000a80425fb
CapEff:	00000000a80425fb
CapBnd:	00000000a80425fb
CapAmb:	0000000000000000
sched_setscheduler: Operation not permitted

As CAP_SYS_NICE is bit 23, we can verify that this bit is not set in CapEff here:

$ python3 -c 'print(0x00000000a80425fb & (1 << 23))'
0

Adding the CAP_SYS_NICE capability allows the sched_setscheduler() call to succeed, and we can see the bit being set in CapEff:

$ docker run --cap-add SYS_NICE fredrikfornwall/cap-sys-nice-docker:0.1
Inspecting /proc/1/status
CapInh:	0000000000000000
CapPrm:	00000000a88425fb
CapEff:	00000000a88425fb
CapBnd:	00000000a88425fb
CapAmb:	0000000000000000
sched_setscheduler: Ok

$ python3 -c 'print(0x00000000a88425fb & (1 << 23))'
8388608

Deploy a kubernetes pod:

$ kubectl apply -f https://raw.githubusercontent.com/fornwall/cap-sys-nice-docker/main/cap-sys-nice-docker.yml
[..]
$ kubectl logs cap-sys-nice-docker
[..]

Note that this pod specifies the following security context for the container:

securityContext:
  capabilities:
    add: ["SYS_NICE"]

cap-sys-nice-docker's People

Contributors

fornwall avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.