SAML 어써션

SAML 어써션 (Assertion)

SAML에서 인증의 결과를 담아 전달하는 핵심 데이터 단위가 바로 **어써션(Assertion)**이에요. IdP(신원 공급자)가 "이 사용자는 이렇게 인증됐고, 이런 속성을 갖고 있어요"라고 XML로 적어서 서비스 공급자(SP)에게 주는 서류라고 보면 되는데요, 이 문서가 신뢰받으려면 서명과 유효기간 조건이 따라붙어요. 이번에는 SAML 2.0 어써션의 뼈대인 <Assertion> 요소와 그 안의 문장(Statement)을 하나씩 살펴볼게요.

출처: Assertions and Protocols for the OASIS Security Assertion Markup Language (SAML) V2.0

본문

SAML 어써션은 XML로 표현되고, XML 네임스페이스 규약을 사용해요. 어써션 구조가 정의된 네임스페이스는 아래 둘이고, 이 규약은 잊지 말아야 할 부분이에요.

  • 어써션 네임스페이스: urn:oasis:names:tc:SAML:2.0:assertion
  • 프로토콜 네임스페이스: urn:oasis:names:tc:SAML:2.0:protocol

또한 XML 서명은 ds:(http://www.w3.org/2000/09/xmldsig#), XML 암호화는 xenc:(http://www.w3.org/2001/04/xmlenc#)로 가져오는데, 어써션 스키마의 헤더를 보면 이 관계가 그대로 드러나요.

<schema targetNamespace="urn:oasis:names:tc:SAML:2.0:assertion"
    xmlns="http://www.w3.org/2001/XMLSchema"
    xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"
    xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
    xmlns:xenc="http://www.w3.org/2001/04/xmlenc#"
    elementFormDefault="unqualified"
    attributeFormDefault="unqualified"
    blockDefault="substitution"
    version="2.0">

<Assertion> 요소의 구조

어써션 하나는 발급자와 서명, 주체(subject), 조건(conditions), 그리고 실제 내용인 문장(statement)들로 이루어져요. <Assertion> 요소는 필수 속성 세 개(Version, ID, IssueInstant)를 요구해요.

<element name="Assertion" type="saml:AssertionType"/>
<complexType name="AssertionType">
    <sequence>
        <element ref="saml:Issuer"/>
        <element ref="ds:Signature" minOccurs="0"/>
        <element ref="saml:Subject" minOccurs="0"/>
        <element ref="saml:Conditions" minOccurs="0"/>
        <element ref="saml:Advice" minOccurs="0"/>
        <choice minOccurs="0" maxOccurs="unbounded">
            <element ref="saml:Statement"/>
            <element ref="saml:AuthnStatement"/>
            <element ref="saml:AuthzDecisionStatement"/>
            <element ref="saml:AttributeStatement"/>
        </choice>
    </sequence>
    <attribute name="Version" type="string" use="required"/>
    <attribute name="ID" type="ID" use="required"/>
    <attribute name="IssueInstant" type="dateTime" use="required"/>
</complexType>

어써션의 문장(statement) 중 실무에서 가장 많이 만나는 건 세 가지예요.

  • 인증 문장(AuthnStatement) — "이 사용자가 언제, 어떻게 인증됐는지"를 담아요.
  • 속성 문장(AttributeStatement) — 사용자에 대한 속성을 전달할 때 써요.
  • 인가 결정 문장(AuthzDecisionStatement) — 특정 리소스 접근을 허용할지 말지를 담아요.

인증 문장의 핵심 스키마는 아래와 같아요. AuthnInstant(인증 시각)가 필수이고, SessionIndex는 세션을 가리키는 값이에요.

<element name="AuthnStatement" type="saml:AuthnStatementType"/>
<complexType name="AuthnStatementType">
    <complexContent>
        <extension base="saml:StatementAbstractType">
            <sequence>
                <element ref="saml:SubjectLocality" minOccurs="0"/>
                <element ref="saml:AuthnContext"/>
            </sequence>
            <attribute name="AuthnInstant" type="dateTime" use="required"/>
            <attribute name="SessionIndex" type="string" use="optional"/>
            <attribute name="SessionNotOnOrAfter" type="dateTime" use="optional"/>
        </extension>
    </complexContent>
</complexType>

주체와 조건

어써션은 "누구에 대한" 내용인지 밝히는데, 그게 <Subject>예요. 주체는 <NameID>처럼 문자열 식별자로 나타내거나, 어써션 전체를 암호화한 <EncryptedID>로 줄 수 있어요.

<element name="Subject" type="saml:SubjectType"/>
<complexType name="SubjectType">
    <choice>
        <sequence>
            <choice>
                <element ref="saml:BaseID"/>
                <element ref="saml:NameID"/>
                <element ref="saml:EncryptedID"/>
            </choice>
            <element ref="saml:SubjectConfirmation" minOccurs="0" maxOccurs="unbounded"/>
        </sequence>
        <element ref="saml:SubjectConfirmation" maxOccurs="unbounded"/>
    </choice>
</complexType>

조건(<Conditions>)은 어써션이 유효한 시점(NotBefore, NotOnOrAfter)과 대상 수신자(AudienceRestriction)를 제한해요. 어써션을 검증할 때는 이 조건들이 지금 통과하는지 반드시 확인해야 해요. 유효기간이 지났거나 의도된 서비스가 아닌데 어써션을 쓰면 안 되니까요.

더 알아보기

  • 브라우저 SSO 플로 — 어써션이 실제로 어떻게 오가는지, 브라우저를 거치는 흐름을 보여줘요.
  • SAML 속성 (AttributeStatement)AttributeStatementAttribute 요소의 구조와 속성 이름 형식.
  • SAML 메타데이터 — IdP와 SP가 서로를 알기 위한 엔티티 문서.
  • SAML 바인딩 — 어써션·프로토콜 메시지를 HTTP로 전달하는 Redirect/POST 방식.