AZ-400: Designing and Implementing Microsoft DevOps Solutions

Design and Implement Authentication and Authorization Methods

Design and implement permissions and roles in GitHub

In this article, we explore how to design and implement permissions and roles in GitHub to effectively manage access and enhance security within your repositories. By defining who can perform specific actions, you can ensure proper collaboration and maintain a secure development environment.

Defining Your Team Structure

Before assigning permissions, clearly define your team structure. Determine who requires access to your repositories and what level of permissions they need. For instance, identify which developers need write or admin access and which users should have read-only privileges.

Adding Collaborators

To add a new collaborator, navigate to one of your repositories (e.g., "My-cool-project") and access its settings by clicking the gear icon. Then, click on Collaborators as illustrated below:

The image shows the settings page of a GitHub repository named "My-cool-project," with options for managing collaborators, branches, and other repository features. The interface is in dark mode, and a cursor is hovering over the "Collaborators" section.

Next, select Add people and enter the GitHub username of the team member—for example, "Coder Lloyd." Once added, the user's status will show as "pending invite." Lloyd must accept the invitation from "Jeremy Morgan KodeKloud" before gaining full access to the repository.

The image shows a GitHub invitation page where a user is invited to collaborate on a project called "My-cool-project," with options to accept or decline the invitation.

After acceptance, you can verify that Lloyd Prismus is listed as a collaborator with appropriate permissions.

Managing Access

Within the Manage access section, you can view both current collaborators and pending invitations. This interface allows you to change each member's access type, switching roles among collaborator, admin, or others based on your repository’s requirements.

The image shows a GitHub repository settings page, specifically the "Manage access" section, where user permissions for a private repository are being managed.

Adjusting Repository Settings

In addition to managing collaborators, GitHub repository settings offer several options to boost security and streamline collaboration:

  • Web-based Commits: Require contributors to sign off on commits made through the web interface, ensuring they adhere to commit protocols.
  • Wikis: Enable wikis to share documentation and guidelines with your team. Note that wiki features may vary based on your GitHub subscription (public repositories for free accounts or private repositories for pro/enterprise subscriptions).
  • Merge Options: Choose from merge commits, squash merging, or rebase merging. At least one merge strategy must be allowed, although you can customize these options to suit your workflow.

Configuring Branch Rules and Protection

When managing multiple developers, setting branch rules and protections is crucial. These policies help monitor branch creation, updates, deletions, and more. For example, you can:

  • Prevent force pushes
  • Require a linear commit history
  • Ensure deployments succeed before merging
  • Mandate signed commits
  • Require pull request reviews before merging

These safeguards ensure that code changes are thoroughly reviewed by team members before they are merged into critical branches.

To create a new branch ruleset:

The image shows a GitHub settings page for a project, specifically the "Rulesets" section, where a user is about to create a new ruleset.

Name your new branch ruleset (e.g., "test") and configure its enforcement status. You can leave some rules disabled until you're ready to enforce them. Additionally, you have the option to add a bypass list—allowing trusted users (like organization admins, deploy key users, or repository admins) to bypass certain rules if necessary.

The image shows a GitHub settings page for a project, specifically focusing on configuring rulesets for branch protection. It includes options for setting a ruleset name, enforcement status, bypass list, and target branches.

You can also target specific branches or patterns. For example, enforce strict rules on staging and production branches while applying more relaxed rules on development branches.

Enforcing Pull Request Reviews

Requiring pull request reviews is a widely adopted practice to ensure code quality. By mandating that changes are validated by at least one other team member, you minimize the risk of errors. Configure the number of required approvals (up to 10 if needed) and ensure that all conversations on a pull request are resolved before merging. Additional controls include:

  • Required status checks (e.g., build and deployment validations)
  • Blocking force pushes
  • Mandating code scanning results for enhanced security

Tip

Consider setting up multiple layers of review to prevent integration of unverified changes.

Configuring Code Security Settings

GitHub offers several features to improve code security. For example, you can enable Dependabot alerts and security updates to monitor vulnerabilities within your dependencies. These tools work for both private and public repositories.

The image shows a GitHub repository settings page focused on "Code security," with options to enable features like Dependabot alerts and security updates. The interface is dark-themed, with a sidebar for navigation.

Setting a Security Policy

Documenting your repository's security policy is essential. Navigate to the Security tab and click on Start setup to create a template that informs users about supported project versions and how to report vulnerabilities. An example Markdown template is shown below:

## Supported Versions

Detail which versions of your project receive security updates.

| Version | Supported           |
|---------|---------------------|
| 5.1.x   | :white_check_mark:  |
| 5.0.x   | :x:                 |
| 4.0.x   | :x:                 |

## Reporting a Vulnerability

Instruct users on how to report vulnerabilities, including where to submit reports, expected response times, and subsequent actions.

Ensure your instructions are clear so users can easily follow the process when a security issue is identified.

Enabling Dependabot Alerts

To enhance repository security, enable Dependabot alerts. This tool monitors your dependencies and automates security updates. If Dependabot alerts are not yet enabled, you will see an interface prompt to activate them:

The image shows a GitHub repository page with Dependabot alerts disabled, indicating that alerts need to be enabled in the repository's settings.

Final Repository Management

Before wrapping up, revisit the Collaborators section in your repository settings to access the Danger Zone. Here you can:

  • Change repository visibility (private or public)
  • Disable branch protection rules
  • Transfer repository ownership
  • Archive or delete the repository

This section is particularly useful when you need to perform major changes such as transferring repository ownership or modifying core settings.

The image shows a GitHub repository settings page, specifically the "Manage access" section, where collaborators can be added or managed for a private repository.

Conclusion

This article provided a comprehensive walkthrough of setting permissions, managing access, configuring branch protection rules, and enabling security features within GitHub repositories. While GitHub Enterprise offers additional complexity, these core principles apply broadly to standard GitHub setups.

Thank you for reading this guide on enhancing your GitHub security and collaboration practices.

Watch Video

Watch video content

Previous
Implement and manage Azure DevOps service connections and personal access tokens