summaryrefslogtreecommitdiff
path: root/lib/gitlab/ci/templates/Security/DAST.latest.gitlab-ci.yml
blob: d1d1c4d7e52fb8dff878f54cba50dba474f84ac0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# To contribute improvements to CI/CD templates, please follow the Development guide at:
# https://docs.gitlab.com/ee/development/cicd/templates.html
# This specific template is located at:
# https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Security/DAST.latest.gitlab-ci.yml

# To use this template, add the following to your .gitlab-ci.yml file:
#
# include:
#   template: DAST.latest.gitlab-ci.yml
#
# You also need to add a `dast` stage to your `stages:` configuration. A sample configuration for DAST:
#
# stages:
#   - build
#   - test
#   - deploy
#   - dast

# Read more about this feature here: https://docs.gitlab.com/ee/user/application_security/dast/

# Configure DAST with CI/CD variables (https://docs.gitlab.com/ee/ci/variables/index.html).
# List of available variables: https://docs.gitlab.com/ee/user/application_security/dast/#available-variables

variables:
  DAST_VERSION: 4
  # Setting this variable will affect all Security templates
  # (SAST, Dependency Scanning, ...)
  SECURE_ANALYZERS_PREFIX: "$CI_TEMPLATE_REGISTRY_HOST/security-products"

dast:
  stage: dast
  image:
    name: "$SECURE_ANALYZERS_PREFIX/dast:$DAST_VERSION"
  variables:
    GIT_STRATEGY: none
  allow_failure: true
  script:
    - export DAST_WEBSITE=${DAST_WEBSITE:-$(cat environment_url.txt)}
    - if [ -z "$DAST_WEBSITE$DAST_API_SPECIFICATION" ]; then echo "Either DAST_WEBSITE or DAST_API_SPECIFICATION must be set. See https://docs.gitlab.com/ee/user/application_security/dast/#configuration for more details." && exit 1; fi
    - /analyze
  artifacts:
    paths:
      - dast_artifacts/*
    reports:
      dast: gl-dast-report.json
  rules:
    - if: $DAST_DISABLED == 'true' || $DAST_DISABLED == '1'
      when: never
    - if: $DAST_DISABLED_FOR_DEFAULT_BRANCH == 'true' &&
          $CI_DEFAULT_BRANCH == $CI_COMMIT_REF_NAME
      when: never
    - if: $DAST_DISABLED_FOR_DEFAULT_BRANCH == '1' &&
          $CI_DEFAULT_BRANCH == $CI_COMMIT_REF_NAME
      when: never
    - if: $CI_DEFAULT_BRANCH != $CI_COMMIT_REF_NAME &&
          $REVIEW_DISABLED == 'true'
      when: never
    - if: $CI_DEFAULT_BRANCH != $CI_COMMIT_REF_NAME &&
          $REVIEW_DISABLED == '1'
      when: never

    # Add the job to merge request pipelines if there's an open merge request.
    - if: $CI_PIPELINE_SOURCE == "merge_request_event" &&
          $GITLAB_FEATURES =~ /\bdast\b/

    # Don't add it to a *branch* pipeline if it's already in a merge request pipeline.
    - if: $CI_OPEN_MERGE_REQUESTS
      when: never

    # Add the job to branch pipelines.
    - if: $CI_COMMIT_BRANCH &&
          $GITLAB_FEATURES =~ /\bdast\b/
  after_script:
    # Remove any debug.log files because they might contain secrets.
    - rm -f /zap/wrk/**/debug.log
    - cp -r /zap/wrk dast_artifacts