DevSecOps یعنی اینکه امنیت را از همان ابتدای توسعه، کنار CI/CD، زیرساخت و عملیات وارد کنیم. در این مسیر، یک مهارت کلیدی این است که «ابزارها» و «دستورهای روزمره» را بلد باشی؛ از بررسی لاگها و سطح دسترسی در لینوکس تا اسکن آسیبپذیری، مدیریت کانتینرها و پیادهسازی امن با IaC.
در ادامه، برای هر تکنولوژی لیستی از دستورات کاربردی میآورم که در کار واقعی (دیباگ، امنیت، اتوماسیون و استقرار) خیلی به کارت میآید.
GitHub • Linux • Docker • Kubernetes • Ansible • Jenkins
اینها بیشتر «اقدامهای رایج» هستند که در GitHub انجام میدهی؛ و معمولاً یا از طریق وب/CLI، یا از طریق تنظیمات و API استفاده میشن. برای سرعت، نسخه CLI هم ذکر میکنم.
1. gh auth login (اتصال به GitHub با CLI)
2. gh auth status (وضعیت احراز هویت)
3. gh repo list (لیست repoهای خودت)
4. gh repo view <owner>/<repo> (مشاهده اطلاعات repo)
5. gh pr list --state open (لیست PRهای باز)
6. gh pr status (وضعیت PR فعلی/منتخب)
7. gh pr checkout <number> (چکاوت PR)
8. gh pr create --title "..." --body "..." (ساخت PR)
9. gh issue list --assignee "@me" (لیست issueهای منتسب به خودت)
10. gh issue create --title "..." --body "..." (ساخت issue)
11. gh api user (اطلاعات کاربر با API)
12. gh api repos/<owner>/<repo>/branches (لیست branchها)
13. gh api repos/<owner>/<repo>/pulls (PRها از طریق API)
14. gh secret list -R <owner>/<repo> (لیست Secretها)
15. gh secret set CI_TOKEN --body "..." -R <owner>/<repo> (Set secret)
16. gh secret delete CI_TOKEN -R <owner>/<repo> (حذف secret)
17. gh workflow list -R <owner>/<repo> (لیست ورکفلوها)
18. gh workflow run <workflow_file> -R <owner>/<repo> --ref <branch> (اجرای ورکفلو)
19. gh run list -R <owner>/<repo> (لیست runها)
20. gh run view <run_id> -R <owner>/<repo> (مشاهده run)
21. gh run download <run_id> -R <owner>/<repo> (دانلود artifactهای run)
22. gh codespace list (لیست codespaceها)
23. gh repo clone <owner>/<repo> (کلون repo)
24. git log --oneline --decorate --graph -n 30 (برای audit تغییرات)
25. git diff <base>...<head> (diff بین دو ref برای بررسی امنیتی)
26. git tag -l (لیست tagها)
27. git branch -vv (دیدن tracking branchها)
28. git status (وضعیت کاری برای جلوگیری از خطا در CI)
29. git checkout -b <name> (ساخت branch جدید)
30. git blame -L <start>,<end> <file> (ردیابی تغییرات در بخشهای حساس)
31. git show <commit> (مشاهده commit)
32. gh repo fork <owner>/<repo> (فورک)
33. gh release create <tag> --generate-notes (ساخت ریلیز)
34. gh release list (لیست ریلیزها)
امنیت در GitHub: استفاده از Branch protection، CODEOWNERS، محدود کردن دسترسی به Secretها، و فعال کردن Dependabot / Code scanning مهم است. (دستورها بیشتر برای مدیریت عملیاند.)
در DevSecOps، لینوکس ستون اصلی است: لاگها، کاربران، سطوح دسترسی، شبکه، و بررسی وضعیت سرویسها.
1. uname -a (اطلاعات کرنل)
2. cat /etc/os-release (نوع سیستم)
3. hostnamectl (نام سیستم و اطلاعات)
4. whoami (نام کاربر فعلی)
5. id (uid/gid و گروهها)
6. sudo -l (مجوزهای sudo)
7. ps aux (لیست فرآیندها)
8. top (مانیتور لحظهای)
9. systemctl status <service> (وضعیت سرویس)
10. systemctl restart <service> (ریست سرویس)
11. systemctl enable <service> (فعالسازی دائمی)
12. journalctl -u <service> -n 200 --no-pager (لاگ سرویس)
13. journalctl -p err --since "24 hours ago" --no-pager (فیلتر خطاها)
14. tail -f /var/log/syslog (مشاهده زنده syslog)
15. tail -f /var/log/auth.log (لاگ احراز هویت)
16. grep -R "Failed password" /var/log/auth.log* | tail -n 50
17. netstat -tulpen (پورتهای باز)
18. ss -tulpen (پورتهای باز با خروجی بهتر)
19. lsof -i -P -n | head (پورتها و پروسهها)
20. ufw status (وضعیت فایروال UFW)
21. iptables -S (قوانین iptables)
22. getenforce (SELinux mode)
23. sestatus (جزئیات SELinux)
24. chmod -R u=rwX,g=rX,o= /path (تنظیم مجوزها)
25. chown -R user:group /path (تغییر مالکیت)
26. umask (پیشفرض mask)
27. find /path -type f -perm -0040000 -ls (یافتن sticky/setuid/setgid)
28. find /etc -type f -name "*.conf" -exec ls -l {} \; | head
29. crontab -l (کرنها)
30. systemctl list-timers (تایمرهای سیستم)
31. ssh -V (نسخه SSH)
32. ssh-audit <host> (اسکن کلاینت/سرور برای سیاستهای SSH* اگر نصب باشد)
33. curl -I https://example.com (بررسی هدرها)
34. dig example.com (DNS)
35. df -h (فضای دیسک)
36. du -sh /var/log/* | sort -h | tail
Docker برای ساخت، اجرای، ایزولهسازی و مدیریت امنیت کانتینرهاست. مهم: کمدسترسترین سطح دسترسی و کمترین سطح privilege.
1. docker version
2. docker info
3. docker images
4. docker ps
5. docker ps -a
6. docker logs <container>
7. docker logs -f --tail 200 <container>
8. docker inspect <container>
9. docker exec -it <container> sh
10. docker exec -it <container> bash
11. docker run --rm -p 8080:80 nginx
12. docker run --read-only ... (فقطخواندنی)
13. docker run --cap-drop=ALL ... (Drop capabilityها)
14. docker run --security-opt=no-new-privileges ... (No new privileges)
15. docker build -t myapp:1.0 .
16. docker build --no-cache -t myapp:1.0 .
17. docker tag myapp:1.0 myrepo/myapp:1.0
18. docker push myrepo/myapp:1.0
19. docker pull myrepo/myapp:1.0
20. docker system df (مصرف دیسک)
21. docker system prune -f (پاکسازی)
22. docker volume ls
23. docker volume inspect <vol>
24. docker network ls
25. docker network inspect <net>
26. docker compose version (اگر Compose نصب باشد)
27. docker compose up -d
28. docker compose down
29. docker compose logs -f --tail 200
30. docker compose config (نمایش خروجی نهایی)
31. docker cp <container>:/path ./ (کپی از کانتینر)
32. docker events --since 1h
33. docker stats (مصرف منابع)
34. docker rm -f $(docker ps -aq) (حذف همه کانتینرها - با احتیاط)
در K8s امنیت و عملیات یعنی: namespace، RBAC، بررسی رویدادها، محدودیت منابع، و بررسی سیاستهای شبکه.
1. kubectl version --client --output=yaml
2. kubectl get nodes -o wide
3. kubectl get ns
4. kubectl config current-context
5. kubectl config get-contexts
6. kubectl describe node <node>
7. kubectl get pods -A
8. kubectl get pods -n <ns>
9. kubectl describe pod <pod> -n <ns>
10. kubectl logs <pod> -n <ns>
11. kubectl logs -f <pod> -n <ns> --tail=200
12. kubectl exec -it <pod> -n <ns> -- sh
13. kubectl apply -f <file>.yaml
14. kubectl delete -f <file>.yaml
15. kubectl get deploy -n <ns>
16. kubectl rollout status deploy/<name> -n <ns>
17. kubectl rollout history deploy/<name> -n <ns>
18. kubectl rollout undo deploy/<name> -n <ns> --to-revision=<n>
19. kubectl get svc -n <ns>
20. kubectl describe svc <svc> -n <ns>
21. kubectl get ingress -A
22. kubectl get events -n <ns> --sort-by=.lastTimestamp
23. kubectl top pod -n <ns> (نیاز به metrics-server)
24. kubectl auth can-i <verb> <resource> --as=<user> (RBAC تست)
25. kubectl auth reconcile -f <rbac.yaml> (در برخی نسخهها)
26. kubectl get role,rolebinding -n <ns>
27. kubectl get clusterrole,clusterrolebinding
28. kubectl api-resources | head
29. kubectl get networkpolicy -A
30. kubectl label pod <pod> -n <ns> key=value
31. kubectl patch deploy <name> -n <ns> --type='merge' -p '{"spec":{"replicas":2}}'
32. kubectl scale deploy/<name> -n <ns> --replicas=2
33. kubectl run test --image=alpine -it --rm
34. kubectl port-forward svc/<svc> 8080:80 -n <ns>
Ansible یعنی اتوماسیون پیکربندی با IaC. برای امنیت: inventory درست، فایلهای حساس، کنترل idempotency.
1. ansible --version
2. ansible all -m ping -i inventory.ini
3. ansible -m setup -i inventory.ini all (جمعآوری facts)
4. ansible-playbook -i inventory.ini site.yml
5. ansible-lint site.yml (اگر نصب باشد)
6. ansible-playbook --syntax-check -i inventory.ini site.yml
7. ansible-playbook --check -i inventory.ini site.yml
8. ansible-playbook --diff -i inventory.ini site.yml
9. ansible-galaxy list
10. ansible-galaxy install geerlingguy.docker
11. ansible-vault create secrets.yml
12. ansible-vault view secrets.yml
13. ansible-vault edit secrets.yml
14. ansible-vault rekey secrets.yml
15. ansible-vault encrypt_string 'mysecret' --name api_key
16. ANSIBLE_CONFIG=./ansible.cfg ansible-playbook -i ... site.yml
17. ansible-inventory -i inventory.ini --list
18. ansible-inventory -i inventory.ini --graph
19. ansible-playbook -i inventory.ini playbook.yml --tags "security"
20. ansible-playbook -i inventory.ini playbook.yml --skip-tags "debug"
21. ansible-playbook play.yml --limit webservers
22. ansible-playbook play.yml --limit 'db:&staging'
23. ansible -m service -a "name=nginx state=restarted" -i inventory.ini web01
24. ansible -m user -a "name=deploy state=present groups=sudo" -i inventory.ini all
25. ansible -m authorized_key -a "user=deploy key='ssh-ed25519 AAA...'" -i inventory.ini all
26. ansible -m copy -a "src=foo dest=/etc/foo mode=0644" -i inventory.ini all
27. ansible -m template -a "src=nginx.conf.j2 dest=/etc/nginx/nginx.conf" -i inventory.ini all
28. ansible -m replace -a "path=/etc/ssh/sshd_config regexp='^#?PasswordAuthentication.*' replace='PasswordAuthentication no'" -i inventory.ini all
29. ansible -m file -a "path=/var/www state=directory owner=www-data group=www-data mode=0755" -i inventory.ini all
30. ansible -m command -a "systemctl is-active nginx" -i inventory.ini all
31. ansible -m shell -a "curl -fsS http://localhost/health || exit 1" -i inventory.ini all
32. ansible-playbook -i inventory.ini harden.yml -v (verbosity)
33. ansible-playbook -i inventory.ini site.yml --vault-password-file ./.vault_pass
34. ansible-doc -l | grep docker (کمک ماژولها)
Jenkins هم ابزار کاراته: مدیریت jobها، مشاهده لاگ، و استفاده از CLI/Pluginها. (بعضی دستورها نیازمند Jenkins CLI و سطح دسترسی است.)
1. java -version
2. systemctl status jenkins
3. systemctl restart jenkins
4. journalctl -u jenkins -n 200 --no-pager
5. cat /var/lib/jenkins/secrets/initialAdminPassword (در نصبهای خاص)
6. docker logs <jenkins_container> (اگر Jenkins با کانتینر است)
7. curl -s -u user:token "http://localhost:8080/api/json"
8. curl -s -u user:token "http://localhost:8080/job/<job>/api/json"
9. curl -X POST -u user:token "http://localhost:8080/job/<job>/build"
10. curl -X POST -u user:token "http://localhost:8080/job/<job>/buildWithParameters?BRANCH=main"
11. curl -s "http://localhost:8080/job/<job>/lastBuild/api/json"
12. curl -s "http://localhost:8080/job/<job>/<build>/consoleText"
13. chmod 600 /var/lib/jenkins/.ssh/*
14. chown -R jenkins:jenkins /var/lib/jenkins
15. ls -la /var/lib/jenkins/workspace/
16. grep -R "ERROR" /var/log/jenkins/ 2>/dev/null | head
17. docker exec -it <jenkins_container> bash
18. docker exec -it <jenkins_container> cat /var/jenkins_home/secrets/initialAdminPassword
19. استفاده از Jenkins Pipeline با Jenkinsfile (عملاً “دستور” نیست ولی روش استاندارد است)
20. ssh-keygen -t ed25519 -C "jenkins" -f /var/lib/jenkins/.ssh/id_ed25519
21. ssh -i /var/lib/jenkins/.ssh/id_ed25519 git@github.com
22. kubectl برای deploy از مرحله Jenkins (دستورهای K8s داخل pipeline)
23. ansible-playbook داخل pipeline (دستور Ansible داخل مرحله)
24. اسکن با trivy fs . (داخل Jenkins) اگر Trivy نصب شود
25. اسکن با grype dir:. (داخل Jenkins) اگر نصب شود
26. امضای image با cosign sign ... اگر نصب شود
27. cosign verify ... اگر نصب شود
28. اجرای npm audit یا yarn audit برای امنیت dependency
29. اجرای mvn -q test یا gradle test (برای CI کیفیت/امنیت)
30. docker build ... + docker push ... داخل pipeline
31. مدیریت credentials via CLI (بسته به نصب: معمولاً با Jenkins CLI یا API)
فایلهای YAML برای Docker و Kubernetes
1) YAML برای Docker (معمولاً از Docker Compose استفاده میشود)
Docker خودش YAML “اصلی” به شکل K8s ندارد، اما docker-compose.yml رایجترین است.
```yaml
# docker-compose.yml
services:
app:
image: myrepo/myapp:1.0
ports:
- "8080:80"
environment:
- APP_ENV=production
restart: unless-stopped
security_opt:
- no-new-privileges:true
read_only: true
```
2) YAML برای Kubernetes (Deployment + Service)
یک نمونه ساده اما امنتر (با حداقل replica و تنظیمات پایه) :
```yaml
# k8s-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp
namespace: default
spec:
replicas: 2
selector:
matchLabels:
app: myapp
template:
metadata:
labels:
app: myapp
spec:
containers:
- name: myapp
image: myrepo/myapp:1.0
ports:
- containerPort: 80
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
runAsNonRoot: true
capabilities:
drop: ["ALL"]
resources:
requests:
cpu: "100m"
memory: "128Mi"
limits:
cpu: "500m"
memory: "256Mi"
---
apiVersion: v1
kind: Service
metadata:
name: myapp
namespace: default
spec:
selector:
app: myapp
ports:
- port: 80
targetPort: 80
type: ClusterIP
```
اگر بخوام خیلی خلاصه بگم:
- GitHub: مدیریت PR/Issue/Secrets/Workflow
- Linux: لاگ، مجوزها، شبکه، سرویسها
- Docker: build/run/push و تنظیم امنیت کانتینر
- Kubernetes: rollout/health/logs و RBAC/Policy
- Ansible: idempotency + vault + hardening
- Jenkins: اجرای pipeline + لاگ + ادغام اسکنها