Skip to content

NimTechnology

Trình bày các công nghệ CLOUD một cách dễ hiểu.

  • Kubernetes & Container
    • Docker
    • Kubernetes
      • Gateway API
      • Ingress
      • Pod
    • Helm Chart
    • OAuth2 Proxy
    • Isito-EnvoyFilter
    • Apache Kafka
      • Kafka
      • Kafka Connect
      • Lenses
    • Vault
    • Longhorn – Storage
    • VictoriaMetrics
    • MetalLB
    • Kong Gateway
  • CI/CD
    • ArgoCD
    • ArgoWorkflows
    • Argo Events
    • Spinnaker
    • Jenkins
    • Harbor
    • TeamCity
    • Git
      • Bitbucket
  • Coding
    • DevSecOps
    • Terraform
      • GCP – Google Cloud
      • AWS – Amazon Web Service
      • Azure Cloud
    • Golang
    • Laravel
    • Python
    • Jquery & JavaScript
    • Selenium
  • Log, Monitor & Tracing
    • DataDog
    • Prometheus
    • Grafana
    • ELK
      • Kibana
      • Logstash
  • BareMetal
    • NextCloud
  • Toggle search form

[Polkit] Apply the Least Privilege principle to service accounts with Polkit.

Posted on August 27, 2026August 27, 2026 By nim No Comments on [Polkit] Apply the Least Privilege principle to service accounts with Polkit.

Hướng dẫn từng bước thực hiện cấu hình phân quyền bằng Polkit từ tài khoản root, giúp người dùng không có đặc quyền điều khiển dịch vụ hệ thống an toàn mà không cần cấp quyền quản trị tối cao.[github][packages.debian]

Contents

Toggle
  • Khởi tạo và kiểm tra ban đầu
  • Kiểm tra và cài đặt Polkit
  • Tạo quy tắc phân quyền
  • Kiểm thử quyền thực thi
  • Giám sát nhật ký phân quyền

Khởi tạo và kiểm tra ban đầu

Đăng nhập bằng tài khoản root và tạo một tài khoản người dùng dịch vụ không có mật khẩu đăng nhập trực tiếp :

# 1. Tạo user komodo-agent
useradd -r -m -d /var/lib/komodo-agent -s /bin/bash komodo-agent

# 2. Thử chạy lệnh restart docker dưới danh nghĩa komodo-agent
su - komodo-agent -c "systemctl restart docker"

Hệ thống sẽ từ chối thực thi và xuất ra thông báo lỗi dạng:

Failed to restart docker.service: Access denied
See system logs and 'systemctl status docker.service' for details.

Kiểm tra và cài đặt Polkit

Tiến hành kiểm tra sự tồn tại của dịch vụ polkit trên hệ thống:[packages.debian][forums.rockylinux]

systemctl status polkit

Nếu hệ thống báo chưa tìm thấy dịch vụ, thực hiện cài đặt theo đúng bản phân phối Linux đang dùng:[forums.rockylinux]

  • Đối với Ubuntu và Debian:
apt-get update && apt-get install -y polkitd
systemctl enable --now polkit
  • Đối với RHEL, Rocky Linux và AlmaLinux:
dnf install -y polkit
systemctl enable --now polkit

Tạo quy tắc phân quyền

Tạo một tệp quy tắc JavaScript trong thư mục /etc/polkit-1/rules.d/ để cấp phép riêng hành động quản lý docker.service cho người dùng komodo-agent:[github]

cat << 'EOF' > /etc/polkit-1/rules.d/50-komodo-docker.rules
polkit.addRule(function(action, subject) {
    if (action.id == "org.freedesktop.systemd1.manage-units" &&
        subject.user == "komodo-agent") {
        
        var unit = action.lookup("unit");
        if (unit == "docker.service") {
            return polkit.Result.YES;
        }
    }
});
EOF

Sau khi tệp được lưu, daemon Polkit sẽ tự động nạp cấu hình mới mà không cần khởi động lại dịch vụ.[github][packages.debian]

Kiểm thử quyền thực thi

Thực hiện chạy lại các lệnh điều khiển hệ thống dưới danh nghĩa komodo-agent để xác thực kết quả:[github]

# 1. Kiểm tra lệnh restart docker (kỳ vọng: chạy thành công)
su - komodo-agent -c "systemctl restart docker"
echo "Ma thoat: $?"

# 2. Kiểm tra lệnh restart một dịch vụ khác như cron/sshd (kỳ vọng: bị chặn)
su - komodo-agent -c "systemctl restart cron"

Lệnh systemctl restart docker sẽ kết thúc với mã thoát 0 (thành công), trong khi lệnh can thiệp vào các dịch vụ khác vẫn bị chặn với lỗi Access denied.[github]

Giám sát nhật ký phân quyền

Quản trị viên có thể theo dõi trực tiếp nhật ký phân quyền của hệ thống bằng công cụ journalctl để xem quá trình Polkit đối chiếu quy tắc:[packages.debian]

journalctl -u polkit -f

Mỗi khi người dùng thực hiện một lệnh hệ thống, nhật ký sẽ ghi lại chi tiết mã hành động, định danh người gọi và kết quả phê duyệt.[github][packages.debian]

BareMetal, Uncategorized

Post navigation

Previous Post: [Kong Gateway] Guide line migrate from Kong Gatway legacy to modern one

More Related Articles

[WordPress] Fix the “Another Update is Currently in Progress” Error in WordPress BareMetal
Running VMware Workstation inside a Windows 11 virtual machine hosted on an ESXi server. Uncategorized
[Smartctl] Instruction check the health disk of Raspberry. BareMetal
[Azure] Boosting Azure Network Performance with Accelerated Networking on AKS Uncategorized
Đường link hỗ trợ các bạn download khoá học trên udemy free! Uncategorized
[Command] Hướng dẫn command xoá file cũ theo ngày trong linux BareMetal

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Tham Gia Group DevOps nhé!
Để Nim có nhiều động lực ra nhiều bài viết.
Để nhận được những thông báo mới nhất.

Recent Posts

  • [Polkit] Apply the Least Privilege principle to service accounts with Polkit. August 27, 2026
  • [Kong Gateway] Guide line migrate from Kong Gatway legacy to modern one August 16, 2026
  • Komodo manages many Docker containers on many servers July 27, 2026
  • [Crunchy] Install PostgreSQL on the k8s cluster via Crunchy Postgres. July 27, 2026
  • [podman] Run a Docker container without using Docker July 15, 2026

Archives

  • August 2026
  • July 2026
  • June 2026
  • April 2026
  • March 2026
  • February 2026
  • January 2026
  • December 2025
  • November 2025
  • October 2025
  • September 2025
  • August 2025
  • July 2025
  • June 2025
  • May 2025
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • July 2024
  • June 2024
  • May 2024
  • April 2024
  • March 2024
  • February 2024
  • January 2024
  • December 2023
  • November 2023
  • October 2023
  • September 2023
  • August 2023
  • July 2023
  • June 2023
  • May 2023
  • April 2023
  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • August 2022
  • July 2022
  • June 2022
  • May 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021

Categories

  • AI
    • OpenClaw
  • BareMetal
    • NextCloud
  • CI/CD
    • Argo Events
    • ArgoCD
    • ArgoWorkflows
    • Git
      • Bitbucket
    • Harbor
    • Jenkins
    • Spinnaker
    • TeamCity
  • Coding
    • DevSecOps
    • Golang
    • Jquery & JavaScript
    • Laravel
    • NextJS 14 & ReactJS & Type Script
    • Python
    • Selenium
    • Terraform
      • AWS – Amazon Web Service
      • Azure Cloud
      • GCP – Google Cloud
  • Kubernetes & Container
    • Apache Kafka
      • Kafka
      • Kafka Connect
      • Lenses
    • Docker
    • Helm Chart
    • Isito-EnvoyFilter
    • Kong Gateway
    • Kubernetes
      • Gateway API
      • Ingress
      • Pod
    • Longhorn – Storage
    • MetalLB
    • OAuth2 Proxy
    • Vault
    • VictoriaMetrics
  • Log, Monitor & Tracing
    • DataDog
    • ELK
      • Kibana
      • Logstash
    • Fluent
    • Grafana
    • Prometheus
  • Uncategorized
  • Admin

Copyright © 2026 NimTechnology.

Powered by PressBook Blog WordPress theme