Skip to main content

Restricting the visibility of forwarded ports

You can set constraints on the visibility options users can choose when they forward ports from codespaces in your organization.

Who can use this feature

To manage access to port visibility constraints for the repositories in an organization, you must be an owner of the organization.

Overview

Typically, within a codespace you are able to forward ports privately (only to yourself), to members of your organization, or publicly (to anyone with the URL). For more information, see "Forwarding ports in your codespace."

As an organization owner, you may want to configure constraints on the visibility options users can set when forwarding ports. For example, for security reasons, you may want to disallow public port forwarding. You do this by defining one or more policies in the GitHub Codespaces settings for your organization.

Behavior when you set a port visibility constraint

If there are existing codespaces that no longer conform to a policy you have defined, these codespaces will continue to operate until they are stopped or time out. When the user resumes the codespace, it will be subject to the policy constraints.

Note: You can't disable private port forwarding, as private port forwarding is required by GitHub Codespaces to continue working as designed, for example to forward SSH on port 22.

Setting organization-wide and repository-specific policies

When you create a policy you choose whether it applies to all repositories in your organization, or only to specified repositories. If you set an organization-wide policy then any policies you set for individual repositories must fall within the restriction set at the organization level. Adding policies makes the choice of visibility options more, not less, restrictive.

For example, you could create an organization-wide policy that restricts the visibility options to organization only. You can then set a policy for Repository A that disallows both public and organization visibility, which would result in only private port forwarding being available for this repository. Setting a policy for Repository A that allowed both public and organization would result in only organization visibility, because the organization-wide policy does not allow public visibility.

If you add an organization-wide policy, you should set it to the most lenient visibility option that will be available for any repository in your organization. You can then add repository-specific policies to further restrict the choice.

: Codespace ポリシーは、組織に課金される codespace のみに適用されます。 個々のユーザーが Organization 内のリポジトリ用の codespace を作成し、その Organization に課金されない場合、codespace はそれらのポリシーに制約されません。 Organization に課金される codespace を作成できるユーザーを選ぶ方法については、「Organization に対してGitHub Codespaces を有効にする」を参照してください。

Adding a policy to limit the port visibility options

  1. GitHub.com の右上隅にあるプロファイル写真をクリックし、 [自分の Organization] をクリックします。 プロファイル メニューの組織

  2. 組織の隣の [設定] をクリックします。 [設定] ボタン

  3. サイドバーの [コード、計画、自動化] セクションで、 [ Codespaces] を選択してから、 [ポリシー] をクリックします。

  4. [codespace ポリシー] ページで、 [ポリシーの作成] をクリックします。

  5. 新しいポリシーの名前を入力します。

  6. Click Add constraint and choose Port visibility.

    Screenshot of the 'Add constraint' dropdown menu

  7. Click to edit the constraint.

    Screenshot of the pencil icon for editing the constraint

  8. Clear the selection of the port visibility options (Org or Public) that you don't want to be available.

    Screenshot of clearing a port visibility option

  9. Click outside of the dialog box to close it.

  10. By default the policy is set to apply to all repositories, if you want it to apply only to some of the repositories in your organization, click All repositories and then click Selected repositories in the dropdown menu.

    Screenshot of choosing 'Selected repositories'

    With Selected repositories selected:

    1. Click .

      Screenshot of the gear icon for editing the settings

    2. Select the repositories you want this policy to apply to.

    3. At the bottom of the repository list, click Select repositories.

      Screenshot of selected repositories for this policy

  11. If you want to add another constraint to the policy, click Add constraint and choose another constraint. For information about other constraints, see:

  12. After you've finished adding constraints to your policy, click Save.

The policy will be applied to all new codespaces that are billable to your organization. The port visibility constraint is also applied to existing codespaces the next time they are started.

Editing a policy

You can edit an existing policy. For example, you may want to add or remove constraints to or from a policy.

  1. Display the "Codespace policies" page. For more information, see "Adding a policy to limit the port visibility options."
  2. Click the name of the policy you want to edit.
  3. Click the pencil icon () beside the "Port visibility" constraint.
  4. Make the required changes then click Save.

Deleting a policy

  1. Display the "Codespace policies" page. For more information, see "Adding a policy to limit the port visibility options."

  2. Click the delete button to the right of the policy you want to delete.

    Screenshot of the delete button for a policy