plaintext
table inet filter {
  chain input {
    type filter hook input priority 0;
    policy drop;

    ct state established,related accept

Host firewall rules with nftables for default deny networking

nftables firewall linux
by Kai Nakamura 1 tab
plaintext
Protocol 2
PermitRootLogin no
PasswordAuthentication no
KbdInteractiveAuthentication no
PubkeyAuthentication yes
AllowUsers deploy ops

SSH daemon hardening and key based access only

ssh linux hardening
by Kai Nakamura 1 tab
yaml
apiVersion: v1
kind: ServiceAccount
metadata:
  name: metrics-reader
  namespace: production
---

Kubernetes RBAC roles with least privilege service accounts

kubernetes rbac least-privilege
by Kai Nakamura 1 tab
yaml
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: api-ingress
  namespace: production
spec:

Kubernetes NetworkPolicy for namespace level traffic control

kubernetes networkpolicy cluster-security
by Kai Nakamura 1 tab
yaml
- name: Build image
  run: docker build -t app:${{ github.sha }} .

- name: Scan image
  uses: aquasecurity/trivy-action@0.24.0
  with:

Trivy image scanning in pull request pipelines

trivy containers ci
by Kai Nakamura 1 tab
dockerfile
FROM ruby:3.3.1-slim AS base

RUN apt-get update \
  && apt-get install -y --no-install-recommends build-essential libpq-dev \
  && rm -rf /var/lib/apt/lists/*

Dockerfile hardening for smaller safer containers

docker containers hardening
by Kai Nakamura 1 tab
bash
#!/usr/bin/env bash
set -euo pipefail

bundle exec bundler-audit check --update
npm audit --audit-level=high
pip-audit --strict

Dependency vulnerability scanning for Ruby and Node projects

dependency-scanning supply-chain ruby
by Kai Nakamura 1 tab
yaml
name: semgrep

on: [pull_request]

jobs:
  scan:

Static application security testing with Semgrep in CI

semgrep sast ci
by Kai Nakamura 1 tab
yaml
repos:
  - repo: https://github.com/gitleaks/gitleaks
    rev: v8.18.4
    hooks:
      - id: gitleaks
  - repo: https://github.com/Yelp/detect-secrets

Git secret scanning with pre commit hooks

git secrets scanning
by Kai Nakamura 1 tab
bash
#!/usr/bin/env bash
set -euo pipefail

export VAULT_ADDR="https://vault.internal:8200"
export VAULT_TOKEN="${VAULT_TOKEN:?missing VAULT_TOKEN}"

Secrets management with environment isolation and Vault

secrets-management vault environment-variables
by Kai Nakamura 1 tab
python
import psycopg

with psycopg.connect(conninfo) as connection:
    with connection.cursor() as cursor:
        cursor.execute(
            'SELECT id, email FROM users WHERE email = %s',

Parameterized queries in Python with psycopg

python sql-injection psycopg
by Kai Nakamura 1 tab
ruby
Rails.application.config.session_store(
  :cookie_store,
  key: '_codesnips_session',
  secure: Rails.env.production?,
  httponly: true,
  same_site: :lax,

Session cookie hardening for browser based authentication

sessions cookies authentication
by Kai Nakamura 1 tab