🔒 Security

ABAC

Attribute-Based Access Control

An attribute-based access control model. Determines permissions dynamically by combining attributes of the user, resource, and environment. Allows finer-grained policy expression than RBAC.

📖 Detailed Explanation

ABAC (Attribute-Based Access Control) is a next-generation access control model defined by NIST. While the traditional RBAC (role-based) relies on a single attribute, the "role," ABAC dynamically determines access by combining various attributes of the Subject, Resource, Action, and Environment. This makes it possible to express complex conditions such as "a marketing team employee accessing customer data from a US IP during working hours."

The core of ABAC is the policy engine (PDP: Policy Decision Point). When an access request comes in, the PEP (Policy Enforcement Point) collects the request context, and the PDP evaluates the policies to decide whether to allow or deny. AWS IAM, Azure RBAC (actually a mix of ABAC), and Kubernetes OPA are representative examples of ABAC implementations. Policies are written in DSLs such as XACML, Rego, and Cedar.

The advantages of ABAC are flexibility and scalability. Even when a new access scenario arises, you only need to modify the attribute-based policies without adding roles. The drawbacks are policy design complexity and performance. As attributes increase, policy evaluation time grows, and detecting policy conflicts or shadow permissions becomes difficult. Large organizations use Policy-Based Access Control (PBAC), which mixes RBAC and ABAC.

ABAC is especially important in AI/ML systems. Model access, dataset permissions, and inference API calls can be controlled with various attributes such as user department, project, data sensitivity, and time zone. Implementing policies such as "a Data Scientist can access only approved training data" in an MLOps platform with ABAC makes it possible to automate data governance.

💻 Code Example

# ABAC Policy - OPA (Open Policy Agent) Rego
package authz

default allow = false

# 정책: 근무시간에 본인 부서 데이터만 접근 허용
allow {
    # 주체(Subject) 속성
    input.user.department == input.resource.department
    input.user.role == "analyst"

    # 환경(Environment) 속성
    is_business_hours(input.context.time)

    # 행위(Action) 속성
    input.action in ["read", "list"]

    # 리소스(Resource) 속성
    input.resource.classification != "top_secret"
}

# 관리자는 모든 접근 허용
allow {
    input.user.role == "admin"
}

# 근무시간 체크 (09:00-18:00)
is_business_hours(time) {
    hour := time_hour(time)
    hour >= 9
    hour < 18
}

# 시간 파싱
time_hour(time) = hour {
    parts := split(time, "T")
    time_parts := split(parts[1], ":")
    hour := to_number(time_parts[0])
}

# 사용 예시 - 요청 데이터
# input = {
#   "user": {"id": "u001", "department": "marketing", "role": "analyst"},
#   "action": "read",
#   "resource": {"type": "customer_data", "department": "marketing", "classification": "internal"},
#   "context": {"time": "2026-01-26T10:30:00Z", "ip": "192.168.1.100"}
# }
# ABAC 구현 - Python Casbin 라이브러리
import casbin

# 모델 정의 (model.conf)
model_text = """
[request_definition]
r = sub, obj, act

[policy_definition]
p = sub_dept, obj_dept, obj_class, act

[policy_effect]
e = some(where (p.eft == allow))

[matchers]
m = r.sub.department == p.sub_dept && \
    r.obj.department == p.obj_dept && \
    r.obj.classification == p.obj_class && \
    r.act == p.act
"""

# 정책 정의 (policy.csv)
# p, marketing, marketing, internal, read
# p, engineering, engineering, internal, read
# p, engineering, engineering, internal, write
# p, admin, *, *, *

class ABACEnforcer:
    def __init__(self):
        self.enforcer = casbin.Enforcer("model.conf", "policy.csv")

    def check_access(self, user: dict, resource: dict, action: str) -> bool:
        """ABAC 정책 평가"""
        return self.enforcer.enforce(user, resource, action)

    def add_policy(self, sub_dept, obj_dept, obj_class, act):
        """정책 동적 추가"""
        self.enforcer.add_policy(sub_dept, obj_dept, obj_class, act)

# 사용 예시
enforcer = ABACEnforcer()

user = {"id": "alice", "department": "marketing", "role": "analyst"}
resource = {"id": "doc-001", "department": "marketing", "classification": "internal"}

# 접근 체크
if enforcer.check_access(user, resource, "read"):
    print("✅ 접근 허용")
else:
    print("❌ 접근 거부")

# AWS Cognito + Lambda ABAC 예시
import boto3

def lambda_handler(event, context):
    """API Gateway Authorizer로 ABAC 구현"""
    claims = event['requestContext']['authorizer']['claims']

    user_attrs = {
        'department': claims.get('custom:department'),
        'clearance': claims.get('custom:clearance_level'),
        'project': claims.get('custom:project_id')
    }

    resource_attrs = extract_resource_attrs(event['resource'])

    # ABAC 평가
    allowed = evaluate_abac_policy(user_attrs, resource_attrs, event['httpMethod'])

    if allowed:
        return generate_policy('Allow', event['methodArn'])
    else:
        return generate_policy('Deny', event['methodArn'])
// AWS IAM Policy - ABAC 예시 (태그 기반)
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "AllowAccessToMatchingProject",
            "Effect": "Allow",
            "Action": [
                "s3:GetObject",
                "s3:PutObject"
            ],
            "Resource": "arn:aws:s3:::data-bucket/*",
            "Condition": {
                // 사용자 태그와 리소스 태그 일치 시 허용
                "StringEquals": {
                    "s3:ExistingObjectTag/project": "${aws:PrincipalTag/project}",
                    "s3:ExistingObjectTag/department": "${aws:PrincipalTag/department}"
                },
                // 근무시간 제한 (선택)
                "DateGreaterThan": {
                    "aws:CurrentTime": "2026-01-01T09:00:00Z"
                },
                "DateLessThan": {
                    "aws:CurrentTime": "2026-12-31T18:00:00Z"
                }
            }
        },
        {
            "Sid": "DenySensitiveDataWithoutClearance",
            "Effect": "Deny",
            "Action": "s3:*",
            "Resource": "arn:aws:s3:::data-bucket/sensitive/*",
            "Condition": {
                "StringNotEquals": {
                    "aws:PrincipalTag/clearance": "top_secret"
                }
            }
        }
    ]
}

// IAM 사용자/역할에 태그 설정
// aws iam tag-user --user-name alice \
//   --tags Key=project,Value=ml-platform Key=department,Value=engineering Key=clearance,Value=secret

// S3 객체에 태그 설정
// aws s3api put-object-tagging --bucket data-bucket --key training-data.csv \
//   --tagging 'TagSet=[{Key=project,Value=ml-platform},{Key=department,Value=engineering}]'

🗣️ Say It Like This in Practice

💬 In an IAM Design Discussion
"With RBAC alone, it is hard to express a policy like 'they are on the marketing team, but can only view customer data from the Korea region.' If you combine department, region, and data classification attributes with ABAC, fine-grained control is possible without role explosion."
💬 In a Cloud Security Review
"To apply ABAC on AWS, you need to manage IAM tags and resource tags consistently. First set up a mandatory-tag policy with SCP, then match user tags and resource tags using variable substitution. That way, access is denied when a tag is missing."
💬 In an MLOps Data Governance Meeting
"Let's control training data access with ABAC. If we attach sensitivity (PII/PHI/Public), project, and approval status tags to datasets and match them against the ML engineer's project assignment, only approved data becomes accessible automatically."

⚠️ Cautions & Best Practices

❌
Adopting ABAC Without Attribute Management

ABAC depends on accurate attribute data. If attributes such as user department and project assignment are not up to date, permission errors occur. Build an attribute synchronization pipeline and regular audits first.

❌
Leaving Policy Conflicts Unaddressed

When multiple ABAC policies conflict, a security hole arises if it is unclear which policy takes precedence. Document conflict resolution rules such as "explicit deny takes precedence," and test with a policy simulator.

❌
Complex Policies Without Considering Performance

When there are many attributes and the conditions are complex, the policy evaluation overhead grows with every request. For engines like OPA, optimize with Partial Evaluation and policy bundling, or add a caching layer.

✅
ABAC Best Practices

We recommend a hybrid approach that defines basic roles with RBAC and refines them with ABAC. Standardize the attribute schema, version-control all policy changes, and regularly conduct access reviews on "who can access what."

🔗 Related Terms

📚 Learn More