2
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のセキュリティ設定をまとめたもの


Rapid Risk Assesment as Code

Risk Assessmentとは

リスクアセスメントはリスクの大きいものから行う

  • 機密データがあるか,特殊要件等
  • platformや言語,フレームワークの脆弱性
  • リスクをレートで測る。

githubでの実装方法

  • docs/以下にrapid-risk-assessment.mdを配置して記載しておく。

Branchのrulesetを使う

作成方法

設定 --> Branches --> Add branch protection rule

一つもブランチがない状態だと設定できないので先にpushをしておく。

  • Require a pull request before merging: mainへpushできなくしてマージリクエストによる更新を行う。
    • Require review from Code Owners: コード所有者が指定されているファイルを変更するプルリクエストでは承認レビューを要求する。 --> 1人の場合はオフにしないとマージリクエストが上げられない
  • Block force pushes: --forceでの上書きを禁止
  • Require Signed Commits: GPGを使ってコミット者を認証できる。
  • Allow deletion: protected branchを削除する権限なのでオフにする。
  • Do not allow bypassing the above settins: 管理者等が上記のルールをバイパスするのを防ぐ。
git push origin master # バイパス設定なしだと
remote: Bypassed rule violations for refs/heads/master:
remote: 
remote: - Changes must be made through a pull request.
remote: 
To github.com:RyosukeDTomita/test.git
   6b1db43..1b8b9a7  master -> master
git push origin master # バイパス設定あり
remote: error: GH006: Protected branch update failed for refs/heads/master.
remote: error: Changes must be made through a pull request.
To github.com:RyosukeDTomita/test.git
 ! [remote rejected] master -> master (protected branch hook declined)
error: failed to push some refs to 'git@github.com:RyosukeDTomita/test.git'

git secrets

  • パスワードのシークレットと思われる文字列を検知する。

環境構築

cd ~/Downloads
wget https://github.com/awslabs/git-secrets/archive/refs/tags/1.3.0.tar.gz
tar zxvf 1.3.0.tar.gz
cd git-secrets-1.3.0/
ls
sudo make install
git secrets # 動作確認

使用方法

  • プロジェクトに移動して以下を実行
git secrets --install
git secrets --register-aws # awsのクレデンシャル検知ルールを登録
git secrets --list # 設定を確認
git secrets --scan # スキャン
  • また,コミットしようとした際にもscanが実行されており,特定の文字列が検知されるとコミットできなくなる。

CODEOWNERS

CODEOWNERS does not stop anyone from editing a file. It only defines who "owns" the file. If a project member edits a file, the owner will be automatically added to the Pull Request approvers list

  • ownerになるとpull requestが行われた時に承認者に追加されるようになる。

  • CODEOWNERSファイルを作成して記述する。コードオーナーについて

  • オーナーになったコードは左上にシールドマークがつく。

/* @RyosukeDTomita

/*.go hoge@gmail.com
/*.txt @SuperHackerOrganaization/admin(Oranaizationの権限ロール)

gitの特殊ファイル

gitignore

vim .gitignore このファイルにコミットしたくないファイルを追加
git rm --cached ファイル名
git add .
git commit -m ""
git push -u origin master

gitignoreを書き方

hoge/ # ディレクトリ全体

.gitkeep

  • 中身が空のファイルをリポジトリに入れておきたい時に慣習として.gitkeepを作り,意味のない内容を記載しておく(空ファイルはコミットできないため)

パッチファイル

  • パッチをあてるのに使う。
git apply patchfile

感想

あとでもうちょい加筆する。一旦Tech Sprintにまにあわせる

2
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
2
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?