Lesson 2 of 6 Security and Compliance Scanning

Configuring GitHub Advanced Security

This lesson explains how the capabilities are packaged and configured on GitHub and for Azure DevOps.

Learning outcomes

After completing this lesson, you will be able to:

  • Describe GitHub Secret Protection and Code Security.
  • Configure CodeQL code scanning.
  • Enable the Azure DevOps form and its tasks.
  • Choose a product from stated requirements.

How it is packaged on GitHub

The capabilities once sold together as GitHub Advanced Security are now sold as two products. GitHub Secret Protection covers secret scanning, push protection and related features. GitHub Code Security covers code scanning with CodeQL, Copilot Autofix, dependency review and security campaigns. They are available for GitHub Team and Enterprise Cloud.

Many features are free for public repositories, including code scanning, secret scanning and push protection. Dependabot alerts, security updates, the dependency graph and SBOM export are available on all plans. A candidate should still recognize the older name, as the skills measured continue to use it.

Sort into groups

Secret Protection or Code Security?

Exam skills 4.3.3

Decide which GitHub product each capability belongs to.

Log in to try this activity Interactive activities are free with an account.

Configuring code scanning on GitHub

Code scanning has two setups. Default setup is enabled with a few clicks in repository or organization settings, and GitHub chooses languages and a schedule. Advanced setup adds a workflow file, which gives control over queries and build steps, and it is needed for custom builds.

name: codeql
on:
  push:
    branches: [main]
  pull_request:
    branches: [main]
  schedule:
    - cron: '20 3 * * 1'

permissions:
  contents: read
  security-events: write

jobs:
  analyze:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        language: [javascript-typescript, python]
    steps:
      - uses: actions/checkout@v4
      - uses: github/codeql-action/init@v3
        with:
          languages: ${{ matrix.language }}
          queries: security-extended
      - uses: github/codeql-action/autobuild@v3
      - uses: github/codeql-action/analyze@v3

The security-events: write permission lets the job upload results, which appear on the Security tab, and in pull requests. Compiled languages may need a manual build instead of autobuild. Third-party tools can add results by uploading a SARIF file.

Scenario questions

Default or advanced setup?

Exam skills 4.3.3

Choose the code scanning setup for each repository.

Log in to try this activity Interactive activities are free with an account.

Configuring secret scanning on GitHub

Enabling secret scanning searches the repository's full history and later pushes for known patterns. Partner patterns notify a provider when a live token is found. Custom patterns use regular expressions for an organization's own secrets. Push protection blocks a push that contains a recognized secret, and the developer can remove it, or bypass with a stated reason, which an organization can require to be reviewed. Security configurations at organization level let an administrator enable features across all repositories.

True or false

Secret scanning and push protection

Exam skills 4.3.3

Check how GitHub secret scanning and push protection behave.

Log in to try this activity Interactive activities are free with an account.

GitHub Advanced Security for Azure DevOps

GitHub Advanced Security for Azure DevOps brings the same engines to Azure Repos. It works only with Git repositories in Azure Repos on Azure DevOps Services, and not with GitHub repositories, and not with Azure DevOps Server. It comes in two packagings. The bundled product combines all features, and GitHub Secret Protection for Azure DevOps and GitHub Code Security for Azure DevOps are standalone. It is billed by active committer.

Enabling it

It can be enabled for one repository, a project or the whole organization from settings, and enabling it begins billing. Push protection and repository secret scanning start automatically, and push protection checks only pushes made after it is enabled.

Pipeline tasks

Code and dependency scanning run as pipeline tasks. The CodeQL tasks wrap a build, and a publish step uploads the results.

steps:
  - task: AdvancedSecurity-Codeql-Init@1
    inputs:
      languages: csharp
      enableAutomaticCodeQLInstall: true

  - script: dotnet build --configuration Release
    displayName: Build

  - task: AdvancedSecurity-Dependency-Scanning@1

  - task: AdvancedSecurity-Codeql-Analyze@1

  - task: AdvancedSecurity-Publish@1

Alerts appear in Repos > Advanced Security, and they can appear in pull request annotations. Two status checks can gate merges: AdvancedSecurity/AllHighAndCritical, and AdvancedSecurity/NewHighAndCritical, which requires a build validation policy. Self-hosted agents need the required URLs to be allowed, and .NET available. Copilot Autofix for Azure DevOps was in limited preview at the time of writing.

The following comparison summarizes the two forms.

On GitHub
RepositoriesGitHub
Enable atRepository or organization
Code scanningDefault setup or workflow
ResultsSecurity tab
Choose when Your code is on GitHub.
For Azure DevOps
RepositoriesAzure Repos Git, Services only
Enable atRepository, project or organization
Code scanningPipeline tasks
ResultsRepos > Advanced Security
Choose when Your code is in Azure Repos.

The following diagram compares three options for blocking credentials at push time in Azure Repos.

Blocking credentials at push time for code in Azure Repos, at the lowest cost. GitHub Secret Protection for Azure DevOps provides push protection and secret alerts without paying for code scanning. Default setup is a GitHub feature, and Microsoft Security DevOps scans in a pipeline after the push.
The scenario is illustrative.
Spot the bug

A CodeQL pipeline that reports nothing

Exam skills 4.3.3

Find the lines that stop GitHub Advanced Security for Azure DevOps from producing results.

Log in to try this activity Interactive activities are free with an account.
Worked example

Choosing the product

A company's code is in Azure Repos, and it wants to block credentials at push time, with the lowest cost. It does not need code scanning yet. What should it enable?

Enable GitHub Secret Protection for Azure DevOps, which provides push protection and secret alerts without paying for code scanning features. Default setup on GitHub is not applicable, because the code is not on GitHub. Microsoft Security DevOps runs tools in a pipeline after a push, and its older CredScan secret scanning has been deprecated.

Check yourself

Which permission does a CodeQL workflow need to upload results?

Show answer

security-events: write. Results then appear on the Security tab.

Exam Tips

Remember for the exam

  • Secret Protection and Code Security replaced the single GitHub purchase.
  • Code scanning uses default setup or an advanced workflow.
  • Results upload needs security-events: write.
  • GitHub Advanced Security for Azure DevOps works with Azure Repos Git only.
  • NewHighAndCritical needs a build validation policy.