Skip to main content

Configuring default setup for code scanning

Quickly set up code scanning to find and fix vulnerable code automatically.

Qui peut utiliser cette fonctionnalité ?

Propriétaires de référentiels, propriétaire d’organisations, gestionnaires de sécurité et utilisateurs avec le rôle d’administrateur

Code scanning est disponible pour les types de référentiels suivants :

  • Des référentiels publics sur GitHub.com
  • Référentiels appartenant à l’organisation sur GitHub Team, GitHub Enterprise Cloud, ou GitHub Enterprise Server, avec GitHub Code Security activé.

We recommend that you start using code scanning with default setup. After you've initially configured default setup, you can evaluate code scanning to see how it's working for you and customize it to better meet your needs. For more information, see À propos des types d’installation pour l’analyse du code.

Prerequisites

Your repository is eligible for default setup for code scanning if:

  • GitHub Actions est activé.
  • Il est visible publiquement, ou GitHub Code Security est activé.

Configuring default setup for a repository

Remarque

If the analyses fail for all CodeQL-supported languages in a repository, default setup will still be enabled, but it will not run any scans or use any GitHub Actions minutes until another CodeQL-supported language is added to the repository or default setup is manually reconfigured, and the analysis of a CodeQL-supported language succeeds.

  1. Sur GitHub, accédez à la page principale du référentiel.

    Remarque

    If you are configuring default setup on a fork, you must first enable GitHub Actions. To enable GitHub Actions, under your repository name, click Actions, then click I understand my workflows, go ahead and enable them. Be aware that this will enable all existing workflows on your fork.

  2. Sous le nom de votre référentiel, cliquez sur Paramètres. Si vous ne voyez pas l’onglet « Paramètres », sélectionnez le menu déroulant , puis cliquez sur Paramètres.

    Capture d’écran d’un en-tête de dépôt montrant les onglets. L’onglet « Paramètres » est mis en évidence avec un encadré orange foncé.

  3. Dans la section « Sécurité » de la barre latérale, cliquez sur Advanced Security.

  4. Sous « Code Security », à droite de « CodeQL analyse », sélectionnez Configurer , puis cliquez sur Défaut.

    Screenshot of the "Code scanning" section of "Advanced Security" settings. The "Default setup" button is highlighted with an orange outline.

    You will then see a "CodeQL default configuration" dialog summarizing the code scanning configuration automatically created by default setup.

  5. Optionally, to customize your code scanning setup, click Edit.

    • To add or remove a language from the analysis performed by default setup, select or deselect that language in the "Languages" section.
    • To specify the CodeQL query suite you would like to use, select your preferred query suite in the "Query suites" section.
  6. Review the settings for default setup on your repository, then click Enable CodeQL. This will trigger a workflow that tests the new, automatically generated configuration.

    Remarque

    If you are switching to default setup from advanced setup, you will see a warning informing you that default setup will override existing code scanning configurations. This warning means default setup will disable the existing workflow file and block any CodeQL analysis API uploads.

  7. If projects in your repository depend on dependencies in private package registries, you can grant code scanning access to them. This can improve the outcomes and quality of analyses. See Accès des fonctionnalités de sécurité aux registres privés.

  8. Optionally, adjust other configuration options which affect default setup. See Propriétés du référentiel pour code scanning.

  9. Optionally, to view your default setup configuration after enablement, select , then click View CodeQL configuration.

Remarque

If no pushes and pull requests have occurred in a repository with default setup enabled for 6 months, the weekly schedule will be disabled to save your GitHub Actions minutes.

Running default setup on self-hosted or exécuteurs plus grands

You can use default setup for all CodeQL-supported languages on self-hosted runners or GitHub-hosted runners.

Remarque

Code scanning sees assigned runners when default setup is enabled. If a runner is assigned to a repository that is already running default setup, you must disable and re-enable default setup to start using the runner. If you add a runner and want to start using it, you can change the configuration manually without needing to disable and re-enable default setup.

Assigning labels to self-hosted runners

To assign a self-hosted runner for default setup, you can use the default code-scanning label, or you can optionally give them custom labels so that individual repositories can use different runners. For information about assigning labels to self-hosted runners, see Utilisation d’étiquettes avec des exécuteurs auto-hébergés.

Once you've assigned custom labels to self-hosted runners, your repositories can use those runners for code scanning default setup.

You can also use security configurations to assign labels to self-hosted runners for code scanning. See Création d’une configuration de sécurité personnalisée.

Assigning exécuteurs plus grands

To assign a exécuteur plus grand, name the runner code-scanning. This will automatically add the code-scanning label to the exécuteur plus grand. An organization can only have one exécuteur plus grand with the code-scanning label, and that runner will handle all code scanning jobs from repositories within your organization with access to the runner's group. See Configuring larger runners for default setup.

Ensuring build support

Default setup uses the none build mode for C/C++, C#, Java et Rust and uses the autobuild build mode for other compiled languages. You should configure your self-hosted runners to make sure they can run all the necessary commands for C/C++, C#, and Swift analysis. Analysis of JavaScript/TypeScript, Go, Ruby, Python, and Kotlin code does not currently require special configuration.

Next steps

After your configuration runs successfully at least once, you can start examining and resolving code scanning alerts. For more information on code scanning alerts, see À propos des alertes d’analyse du code and Évaluation des alertes d’analyse du code pour votre référentiel.

After you've configured default setup for code scanning, you can read about evaluating how it's working for you and the next steps you can take to customize it. For more information, see Évaluation de la configuration par défaut pour l’analyse du code.

You can find detailed information about your code scanning configuration, including timestamps for each scan and the percentage of files scanned, on the tool status page. For more information, see Use the tool status page for code scanning.

When you configure default setup, you may encounter an error. For information on troubleshooting specific errors, see Résolution des erreurs d’analyse du code.