バージョンごとのドキュメント一覧

50.3. OAuth検証器コールバック #

<title>OAuth Validator Callbacks</title>

OAuth validator modules implement their functionality by defining a set of callbacks. The server will call them as required to process the authentication request from the user. OAuth検証器モジュールは、一連のコールバックを定義することでその機能を実装します。 サーバは、ユーザからのプロセス認証リクエストを処理するために、必要に応じてそれらを呼び出します。

50.3.1. スタートアップコールバック #

<title>Startup Callback</title>

The <function>startup_cb</function> callback is executed directly after loading the module. This callback can be used to set up local state and perform additional initialization if required. If the validator module has state it can use <structfield>state->private_data</structfield> to store it. startup_cbコールバックは、モジュールのロード直後に実行されます。 このコールバックは、ローカルの状態を設定し、必要に応じて追加の初期設定を実行するために使用できます。 検証器モジュールに状態がある場合は、state->private_dataを使用してそれを格納できます。

typedef void (*ValidatorStartupCB) (ValidatorModuleState *state);

50.3.2. 検証コールバック #

<title>Validate Callback</title>

The <function>validate_cb</function> callback is executed during the OAuth exchange when a user attempts to authenticate using OAuth. Any state set in previous calls will be available in <structfield>state->private_data</structfield>. validate_cbコールバックは、ユーザがOAuthを使用して認証しようとするときに、OAuth交換中に実行されます。 以前の呼び出しで設定された状態は、state->private_dataで使用できます。

typedef bool (*ValidatorValidateCB) (const ValidatorModuleState *state,
                                     const char *token, const char *role,
                                     ValidatorModuleResult *result);

<replaceable>token</replaceable> will contain the bearer token to validate. <application>PostgreSQL</application> has ensured that the token is well-formed syntactically, but no other validation has been performed. <replaceable>role</replaceable> will contain the role the user has requested to log in as. The callback must set output parameters in the <literal>result</literal> struct, which is defined as below: トークンには、検証対象のベアラトークンが含まれます。 PostgreSQLは、トークンが構文的に整形式であることを確認していますが、他のバリデーションは実行されていません。 ロールには、ユーザがログインとして要求したロールが含まれます。 コールバックはresult構造体に出力パラメータを設定する必要があり、これは次のように定義されます。

typedef struct ValidatorModuleResult
{
    bool        authorized;
    char       *authn_id;
} ValidatorModuleResult;

The connection will only proceed if the module sets <structfield>result->authorized</structfield> to <literal>true</literal>. To authenticate the user, the authenticated user name (as determined using the token) shall be palloc'd and returned in the <structfield>result->authn_id</structfield> field. Alternatively, <structfield>result->authn_id</structfield> may be set to NULL if the token is valid but the associated user identity cannot be determined. モジュールがresult->authorizedtrueに設定した場合のみ、コネクションが続行されます。 ユーザを認証するために、認証されたユーザ名(トークンを使用して決定されたもの)はpallocされ、result->authn_idフィールドで返される必要があります。 または、result->authn_idトークンが有効であるが、関連付けられたユーザIDを決定できない場合は、NULLに設定される場合があります。

A validator may return <literal>false</literal> to signal an internal error, in which case any result parameters are ignored and the connection fails. Otherwise the validator should return <literal>true</literal> to indicate that it has processed the token and made an authorization decision. 検証器は、内部エラーを示すためにfalseを返すことができ、この場合、すべての結果パラメータが無視され、接続は失敗します。 そうでない場合、検証器はtrueを返して、トークンを処理し、認可決定を行ったことを示す必要があります。

The behavior after <function>validate_cb</function> returns depends on the specific HBA setup. Normally, the <structfield>result->authn_id</structfield> user name must exactly match the role that the user is logging in as. (This behavior may be modified with a usermap.) But when authenticating against an HBA rule with <literal>delegate_ident_mapping</literal> turned on, <productname>PostgreSQL</productname> will not perform any checks on the value of <structfield>result->authn_id</structfield> at all; in this case it is up to the validator to ensure that the token carries enough privileges for the user to log in under the indicated <replaceable>role</replaceable>. validate_cbが返された後の動作は、特定のHBA設定によって異なります。 通常、result->authn_idユーザ名は、ユーザがログインしようとしているロールと正確に一致する必要があります。 (この振る舞いはユーザマップで変更できます。) しかし、delegate_ident_mappingが有効なHBAルールに対して認証する場合、PostgreSQLresult->authn_idの値をまったくチェックしません。この場合、トークンが指示されたroleの下でユーザがログインするのに十分な権限を持つかどうかは、検証器に委ねられます。

50.3.3. シャットダウンコールバック #

<title>Shutdown Callback</title>

The <function>shutdown_cb</function> callback is executed when the backend process associated with the connection exits. If the validator module has any allocated state, this callback should free it to avoid resource leaks. shutdown_cbコールバックは、接続に関連付けられたバックエンドプロセスが終了するときに実行されます。 検証器モジュールにメモリを割り当てられた状態がある場合、このコールバックはリソースリークを回避するためにフリーする必要があります。

typedef void (*ValidatorShutdownCB) (ValidatorModuleState *state);