0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Github Codespaces でシークレットキーを安全に管理する

Posted at

目的

Azure Storage のアクセスキー(接続文字列)を安全に管理しながら、Github Codespaces でC# アプリケーションをデバッグしたい。

対策

Github Secrets にアクセスキーを登録し、C#コードは環境変数として読み込む。

手順

  1. Github の Settings から Codespaces を開く

  2. Secrets の Codespace user secrets にアクセスキー(接続文字列)を登録する

  3. Github Codespaces でデバッグしたいC#アプリケーションのリポジトリを開く

  4. [Code] - […] - [Configure dev container] を選択する

  5. .devcontainer ディレクトリの devcontainer.json に設定を追加する
    今回は環境変数名とシークレット名がどちらも「STORAGE_CONNECTION_STRING」

      "remoteEnv": {
        "STORAGE_CONNECTION_STRING": "${secrets.STORAGE_CONNECTION_STRING}"
      },
    
  6. 開発コンテナーをリビルドする

  7. 環境変数(今回は「STORAGE_CONNECTION_STRING」)から接続文字列を取得する様にプログラムを修正する

    string? storageConnectionString = Environment.GetEnvironmentVariable("STORAGE_CONNECTION_STRING");
    

参考サイト

GitHub Codespaces のアカウント固有のシークレットの管理

開発コンテナーの概要

GitHub Codespaces 用に C# (.NET) プロジェクトを設定する

codespace でのコンテナーのリビルド

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?