Skip to content

[false positive] MaximumRetryCount is not set to 5: #521

@andreagalle

Description

@andreagalle

I keep getting the false positive below (in section 5.14 of you report) running the v1.5.0 docker-bench-security.sh script on my env

  [WARN] 5.14 - Ensure that the 'on-failure' container restart policy is set to '5' (Automated)
  [WARN]       * MaximumRetryCount is not set to 5: my-stack_working-test.1.hn66bykaqaxp2r0jkxjkb4lyb

even if the MaximumRetryCount is properly configured (or better. the "MaxAttempts" one)

  [root@172 test]# docker service inspect my-stack_working-test | grep -in "MaxAttempts" -B 5 -A 5 --color
  28-                },
  29-                "Resources": {},
  30-                "RestartPolicy": {
  31-                    "Condition": "on-failure",
  32-                    "Delay": 5000000000,
  33:                    "MaxAttempts": 5
  34-                },
  35-                "Placement": {},
  36-                "Networks": [
  37-                    {
  38-                        "Target": "hwiiab56tunn7gtaiur4tmngk",
  [root@172 test]# docker service inspect my-stack_crashing-test | grep -in "MaxAttempts" -B 5 -A 5 --color
  28-                },
  29-                "Resources": {},
  30-                "RestartPolicy": {
  31-                    "Condition": "on-failure",
  32-                    "Delay": 5000000000,
  33:                    "MaxAttempts": 5
  34-                },
  35-                "Placement": {},
  36-                "Networks": [
  37-                    {
  38-                        "Target": "hwiiab56tunn7gtaiur4tmngk",

and working as expected:

  [root@172 test]# docker service ps my-stack_working-test --no-trunc
  ID                          NAME                      IMAGE               NODE            DESIRED STATE   CURRENT STATE           ERROR     PORTS
  hn66bykaqaxp2r0jkxjkb4lyb   my-stack_working-test.1   work-image:latest   ***.**.***.**   Running         Running 9 minutes ago
  [root@172 test]# docker service ps my-stack_crashing-test --no-trunc
  ID                          NAME                           IMAGE                NODE            DESIRED STATE   CURRENT STATE          ERROR                       PORTS
  xjq2q8czw441u5kfhhwg0eybn   my-stack_crashing-test.1       crash-image:latest   ***.**.***.**   Shutdown        Failed 9 minutes ago   "task: non-zero exit (1)"
  2fq1qcratulyzw64jgxqeauz9    \_ my-stack_crashing-test.1   crash-image:latest   ***.**.***.**   Shutdown        Failed 9 minutes ago   "task: non-zero exit (1)"
  74av33ziti9rz58i5ojwbvqr2    \_ my-stack_crashing-test.1   crash-image:latest   ***.**.***.**   Shutdown        Failed 9 minutes ago   "task: non-zero exit (1)"
  rbzswrlkkepm4g7rmb2hjcliv    \_ my-stack_crashing-test.1   crash-image:latest   ***.**.***.**   Shutdown        Failed 9 minutes ago   "task: non-zero exit (1)"
  x28qnn1t4yi72dcyana2zh6ty    \_ my-stack_crashing-test.1   crash-image:latest   ***.**.***.**   Shutdown        Failed 9 minutes ago   "task: non-zero exit (1)"
  a454ffhssmb2hobamq5bdt33e    \_ my-stack_crashing-test.1   crash-image:latest   ***.**.***.**   Shutdown        Failed 9 minutes ago   "task: non-zero exit (1)"

I made couple tests on the following Docker images (below everything to reproduce this issue):

  1. first service (working one) is built from the Dockerfile below:

     FROM alpine:latest
     
     CMD sh -c "ping localhost"
    
  2. second service (crashing one) is built from the Dockerfile below:

     FROM alpine:latest
     
     CMD sh -c "exit 1"
    

The two services are deployed, from the following stack-file.yml

  version: "3.9"
  
  services:
    working-test:
      image: work-image:latest
      deploy:
        restart_policy:
          max_attempts: 5
          condition: on-failure
    crashing-test:
      image: crash-image:latest
      deploy:
        restart_policy:
          max_attempts: 5
          condition: on-failure

to docker swarm, with this command:

  docker stack deploy --compose-file stack-file.yml my-stack

What's wrong with the above configuration, or rather with the docker-bench-security.sh utility, when it checks for the MaximumRetryCount that seems to me properly configured and working as expected? Maybe this is just an issue of misalignment between these two properties?

  • MaximumRetryCount
  • MaxAttempts

I am using Docker version 23.0.1:

  [root@172 docker-bench-security-1.5.0]# docker version
  Client: Docker Engine - Community
   Version:           23.0.1
   API version:       1.42
   Go version:        go1.19.5
   Git commit:        a5ee5b1
   Built:             Thu Feb  9 19:51:00 2023
   OS/Arch:           linux/amd64
   Context:           default
  
  Server: Docker Engine - Community
   Engine:
    Version:          23.0.1
    API version:      1.42 (minimum version 1.12)
    Go version:       go1.19.5
    Git commit:       bc3805a
    Built:            Thu Feb  9 19:48:42 2023
    OS/Arch:          linux/amd64
    Experimental:     false
   containerd:
    Version:          1.6.18
    GitCommit:        2456e983eb9e37e47538f59ea18f2043c9a73640
   runc:
    Version:          1.1.4
    GitCommit:        v1.1.4-0-g5fd4c4d
   docker-init:
    Version:          0.19.0
    GitCommit:        de40ad0

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions