Skip to content

Latest commit

 

History

History
109 lines (78 loc) · 5.89 KB

generate-http-signature.md

File metadata and controls

109 lines (78 loc) · 5.89 KB
description
This page provides the technical details of the Generate HTTP Signature policy

Generate HTTP Signature

Overview

HTTP Signature is an authentication method for adding additional security.

Functional and implementation information for the generate-http-signature policy is organized into the following sections:

Examples

{% hint style="warning" %} This policy can be applied to v2 APIs and v4 HTTP proxy APIs. It cannot be applied to v4 message APIs or v4 TCP proxy APIs. {% endhint %}

{% tabs %} {% tab title="HTTP proxy API example" %} Sample policy configuration:

{
  "generate-http-signature": {
	"scheme":"AUTHORIZATION",
	"validityDuration":30,
	"keyId":"my-key-id",
	"secret":"my-passphrase",
	"algorithm":"HMAC_SHA256",
	"headers":["X-Gravitee-Header","Host"],
    "created": true,
    "expires": true
  }
}

{% endtab %} {% endtabs %}

Configuration

The Signature authentication model requires the client to authenticate itself with a digital signature produced by either a private asymmetric key (e.g., RSA) or a shared symmetric key (e.g., HMAC).

To authenticate, clients can use Authorization header or Signature header. For example:

  • Authorization: Signature "keyId="rsa-key-1",created=1630590825,expires=1630590831061,algorithm="hmac-sha256",headers="host",signature="Ib/KOuoDjyZPmLbKPvrnz+wj/kcEFZt5aPCxF4e7tO0="",
  • Signature: "keyId="rsa-key-1",created=1630590825,expires=1630590831061,algorithm="hmac-sha256",headers="host",signature="Ib/KOuoDjyZPmLbKPvrnz+wj/kcEFZt5aPCxF4e7tO0="",

{% hint style="info" %} The current version of the policy does not support Digest, (request-target), Host, or Path headers. {% endhint %}

Sample policy configuration is shown below:

{% code title="Sample Configuration" %}

{
  "name": "Custom name",
  "description": "Adds HTTP signature auth",
  "policy": "generate-http-signature",
  "configuration": {
	"scheme": "AUTHORIZATION",
	"validityDuration": 30,
	"keyId": "my-key-id",
	"secret": "my-passphrase",
	"algorithm": "HMAC_SHA256",
	"headers": ["X-Gravitee-Header","Host"],
    	"created": true,
   	"expires": true
  }
}

{% endcode %}

Phases

The phases checked below are supported by the generate-http-signature policy:

v2 PhasesCompatible?v4 PhasesCompatible?
onRequesttrueonRequesttrue
onResponsefalseonResponsefalse
onRequestContentfalseonMessageRequestfalse
onResponseContentfalseonMessageResponsefalse

Options

You can configure the generate-http-signature policy with the following options:

PropertyRequiredDescriptionDefaultExample
schemetrueSignature Scheme (authorization header or signature header)authorization-
keyIdtrueThe key ID used to generate the signature (supports EL)-rsa-key-1
secrettrueThe secret key used to generate and verify the signature (supports EL)-passphrase
algorithmtrueThe HMAC digest algorithmHMAC_SHA256-
headersfalseList of headers to build the signature. If no headers, the request must at least contains Date header.--
createdtrueInclude the created timestamp in the signature and (created) headertrue-
expirestrueInclude the expires timestamp in the signature and (expires) headertrue-
validityDurationfalseSignature’s maximum validation duration in seconds (minimum is 1). Applied when expires is set to true.3-

Compatibility matrix

The following is the compatibility matrix for APIM and the generate-http-signature policy:

Plugin VersionSupported APIM versions
Up to 1.xAll

Errors

HTTP status codeDescription
400
  • Request does not contain every header in the configuration headers list.
  • Request does not contain Date header and the configuration headers list is empty. Policy needs at least Date header to create a signature.
  • Unable to sign because of bad configuration.

You can override the default response provided by the policy via the response templates feature. These templates must be defined at the API level (see Response Templates from the Proxy menu). The following keys are sent by the generate-http-signature policy:

KeyParameters
HTTP_SIGNATURE_IMPOSSIBLE_GENERATION-

Changelogs

{% @github-files/github-code-block url="https://github.com/gravitee-io/gravitee-policy-generate-http-signature/blob/master/CHANGELOG.md" %}