⚖️ AI Regulation & Ethics

Right to Consent

The right to consent to the processing of personal data

Detailed Explanation

The Right to Consent is the right of individuals to consent to or refuse the processing of their personal data. It is established as a key legal basis for processing in Articles 6 and 7 of the GDPR and Article 15 of the Korean Personal Information Protection Act. In the AI context, obtaining consent is especially important when collecting training data.

Under the GDPR, valid consent must meet four requirements: freely given, specific, informed, and unambiguous. Blanket consent or pre-ticked consent boxes are not valid. Consent for AI training purposes must be specific, such as "Your data will be used to train AI models."

The Korean Personal Information Protection Act requires that, when obtaining consent, the purpose of processing, the items collected, the retention period, and the right to refuse consent and any disadvantages resulting from refusal be disclosed (Article 15, Paragraph 2). In particular, processing sensitive information (such as health or political opinions) requires separate, explicit consent.

The difficulty of managing consent in AI development is removing the influence of the relevant data from a model that has already been trained when consent is withdrawn. Machine Unlearning techniques are being researched, but in practice retraining the model may be necessary. Therefore, a data architecture that takes the scope of consent and the possibility of withdrawal into account in advance is important.

Code Example

# 동의 관리 시스템 구현 예제
from dataclasses import dataclass, field
from datetime import datetime
from typing import List, Dict, Optional
from enum import Enum
import uuid
import hashlib

class ConsentPurpose(Enum):
    """동의 목적 (GDPR 제6조 기반)"""
    SERVICE_PROVISION = "service_provision"      # 서비스 제공
    AI_TRAINING = "ai_training"                  # AI 모델 학습
    AI_PERSONALIZATION = "ai_personalization"   # AI 개인화
    MARKETING = "marketing"                      # 마케팅
    RESEARCH = "research"                        # 연구 목적
    THIRD_PARTY_SHARING = "third_party_sharing" # 제3자 제공

class ConsentStatus(Enum):
    GRANTED = "granted"
    WITHDRAWN = "withdrawn"
    EXPIRED = "expired"

@dataclass
class ConsentRecord:
    """개별 동의 기록"""
    consent_id: str
    user_id: str
    purpose: ConsentPurpose
    status: ConsentStatus
    granted_at: datetime
    withdrawn_at: Optional[datetime] = None
    expiry_date: Optional[datetime] = None
    version: str = "1.0"  # 동의 약관 버전
    ip_address: Optional[str] = None
    proof_hash: str = field(default="")  # 동의 증빙 해시

    def __post_init__(self):
        if not self.proof_hash:
            # 동의 증빙용 해시 생성
            content = f"{self.user_id}:{self.purpose.value}:{self.granted_at}"
            self.proof_hash = hashlib.sha256(content.encode()).hexdigest()

class ConsentManager:
    """GDPR/개인정보보호법 준수 동의 관리 시스템"""

    def __init__(self):
        self.consents: Dict[str, List[ConsentRecord]] = {}  # user_id -> consents

    def grant_consent(self, user_id: str, purpose: ConsentPurpose,
                      expiry_days: int = 365, version: str = "1.0") -> ConsentRecord:
        """동의 획득 (GDPR 제7조 요건 준수)"""
        consent = ConsentRecord(
            consent_id=str(uuid.uuid4())[:8],
            user_id=user_id,
            purpose=purpose,
            status=ConsentStatus.GRANTED,
            granted_at=datetime.now(),
            expiry_date=datetime.now().replace(
                year=datetime.now().year + (expiry_days // 365)
            ) if expiry_days else None,
            version=version
        )

        if user_id not in self.consents:
            self.consents[user_id] = []
        self.consents[user_id].append(consent)

        print(f"[동의 획득] 사용자 {user_id}, 목적: {purpose.value}")
        return consent

    def withdraw_consent(self, user_id: str, purpose: ConsentPurpose) -> bool:
        """동의 철회 (GDPR 제7조 제3항: 동의 철회는 동의만큼 쉬워야 함)"""
        if user_id not in self.consents:
            return False

        for consent in self.consents[user_id]:
            if consent.purpose == purpose and consent.status == ConsentStatus.GRANTED:
                consent.status = ConsentStatus.WITHDRAWN
                consent.withdrawn_at = datetime.now()
                print(f"[동의 철회] 사용자 {user_id}, 목적: {purpose.value}")
                print(f"  -> AI 학습 데이터 제외 처리 필요")
                return True
        return False

    def check_consent(self, user_id: str, purpose: ConsentPurpose) -> bool:
        """특정 목적에 대한 유효한 동의 존재 여부 확인"""
        if user_id not in self.consents:
            return False

        for consent in self.consents[user_id]:
            if consent.purpose == purpose:
                if consent.status == ConsentStatus.GRANTED:
                    # 만료 여부 확인
                    if consent.expiry_date and consent.expiry_date < datetime.now():
                        consent.status = ConsentStatus.EXPIRED
                        return False
                    return True
        return False

    def get_users_with_consent(self, purpose: ConsentPurpose) -> List[str]:
        """특정 목적에 동의한 사용자 목록 (AI 학습 데이터 필터링용)"""
        users = []
        for user_id, user_consents in self.consents.items():
            if self.check_consent(user_id, purpose):
                users.append(user_id)
        return users

    def get_withdrawn_users(self, purpose: ConsentPurpose,
                            since: datetime = None) -> List[str]:
        """동의 철회 사용자 목록 (Machine Unlearning 대상)"""
        users = []
        for user_id, user_consents in self.consents.items():
            for consent in user_consents:
                if consent.purpose == purpose and consent.status == ConsentStatus.WITHDRAWN:
                    if since is None or (consent.withdrawn_at and consent.withdrawn_at >= since):
                        users.append(user_id)
                        break
        return users

    def generate_consent_audit_log(self, user_id: str) -> Dict:
        """감사용 동의 이력 생성 (GDPR 제7조 제1항: 동의 증명 의무)"""
        if user_id not in self.consents:
            return {"user_id": user_id, "consents": []}

        return {
            "user_id": user_id,
            "consents": [
                {
                    "consent_id": c.consent_id,
                    "purpose": c.purpose.value,
                    "status": c.status.value,
                    "granted_at": c.granted_at.isoformat(),
                    "withdrawn_at": c.withdrawn_at.isoformat() if c.withdrawn_at else None,
                    "version": c.version,
                    "proof_hash": c.proof_hash
                }
                for c in self.consents[user_id]
            ]
        }

# 사용 예시
cm = ConsentManager()

# AI 학습 목적 동의 획득
cm.grant_consent("user_001", ConsentPurpose.AI_TRAINING)
cm.grant_consent("user_002", ConsentPurpose.AI_TRAINING)
cm.grant_consent("user_003", ConsentPurpose.AI_TRAINING)

# 학습 데이터 필터링 (동의한 사용자만)
consented_users = cm.get_users_with_consent(ConsentPurpose.AI_TRAINING)
print(f"AI 학습 가능 사용자: {consented_users}")

# 동의 철회 처리
cm.withdraw_consent("user_002", ConsentPurpose.AI_TRAINING)

# 철회 사용자 데이터 처리 (재학습 또는 unlearning)
withdrawn = cm.get_withdrawn_users(ConsentPurpose.AI_TRAINING)
print(f"데이터 제외 필요: {withdrawn}")

Practical Conversation

PM: How should we handle it when a user withdraws consent for AI training?

Legal team: Under Article 7 of the GDPR, withdrawing consent must be as easy as giving it, and it does not affect the lawfulness of processing carried out before withdrawal, but after withdrawal the data can no longer be used.

ML engineer: What about models that have already been trained?

Legal team: Ideally Machine Unlearning would be used, but in practice it may be necessary to exclude the data and retrain. This should be taken into account when designing the data architecture.

Interviewer: Please explain the requirements for valid consent under the GDPR.

Candidate: According to Article 7 of the GDPR, valid consent must meet four requirements. It must be freely given (refusal is possible without detriment), specific (separate consent for each purpose), informed (the processing is understood), and unambiguous (an affirmative act is required). The AI training purpose must be separated into its own consent item, and a means of withdrawing consent must also be provided easily.

Senior: The consent verification logic is missing from the data loader.

Junior: Even though the data is already filtered when it is pulled from the DB?

Senior: Consent can be withdrawn in the meantime. Add logic that rechecks the consent status in real time right before training. This is essential especially for long-running training jobs.

Take a mock interview on this topic → WIA SOOM AI Interview · Start for free

Cautions

Learn More