amazonka-1.5.0: Comprehensive Amazon Web Services SDK.

Copyright(c) 2013-2017 Brendan Hay
LicenseMozilla Public License, v. 2.0.
MaintainerBrendan Hay <brendan.g.hay+amazonka@gmail.com>
Stabilityprovisional
Portabilitynon-portable (GHC extensions)
Safe HaskellNone
LanguageHaskell2010

Network.AWS.Auth

Contents

Description

Explicitly specify your Amazon AWS security credentials, or retrieve them from the underlying OS.

The format of environment variables and the credentials file follows the official AWS SDK guidelines.

Synopsis

Authentication

Retrieving Authentication

getAuth :: (Applicative m, MonadIO m, MonadCatch m) => Manager -> Credentials -> m (Auth, Maybe Region) Source #

Retrieve authentication information via the specified Credentials mechanism.

Throws AuthError when environment variables or IAM profiles cannot be read, and credentials files are invalid or cannot be found.

data Credentials Source #

Determines how AuthN/AuthZ information is retrieved.

Constructors

FromKeys AccessKey SecretKey

Explicit access and secret keys. See fromKeys.

FromSession AccessKey SecretKey SessionToken

Explicit access key, secret key and a session token. See fromSession.

FromEnv Text Text (Maybe Text) (Maybe Text)

Lookup specific environment variables for access key, secret key, an optional session token, and an optional region, respectively.

FromProfile Text

An IAM Profile name to lookup from the local EC2 instance-data. Environment variables to lookup for the access key, secret key and optional session token.

FromFile Text FilePath

A credentials profile name (the INI section) and the path to the AWS credentials file.

FromContainer

Obtain credentials by attempting to contact the ECS container agent at http://169.254.170.2 using the path in envContainerCredentialsURI. See IAM Roles for Tasks in the AWS documentation for more information.

Discover

Attempt credentials discovery via the following steps:

  • Read the envAccessKey, envSecretKey, and envRegion from the environment if they are set.
  • Read the credentials file if credFile exists.
  • Obtain credentials from the ECS container agent if envContainerCredentialsURI is set.
  • Retrieve the first available IAM profile and read the Region from the instance identity document, if running on EC2.

An attempt is made to resolve http://instance-data rather than directly retrieving http://169.254.169.254 for IAM profile information. This assists in ensuring the DNS lookup terminates promptly if not running on EC2.

data Auth :: * #

An authorisation environment containing AWS credentials, and potentially a reference which can be refreshed out-of-band as temporary credentials expire.

Instances

ToLog Auth 

Methods

build :: Auth -> Builder #

Defaults

Environment

envAccessKey Source #

Arguments

:: Text

AWS_ACCESS_KEY_ID

Default access key environment variable.

envSecretKey Source #

Arguments

:: Text

AWS_SECRET_ACCESS_KEY

Default secret key environment variable.

envSessionToken Source #

Arguments

:: Text

AWS_SESSION_TOKEN

Default session token environment variable.

Credentials File

credAccessKey Source #

Arguments

:: Text

aws_access_key_id

Credentials INI file access key variable.

credSecretKey Source #

Arguments

:: Text

aws_secret_access_key

Credentials INI file secret key variable.

credSessionToken Source #

Arguments

:: Text

aws_session_token

Credentials INI file session token variable.

credProfile Source #

Arguments

:: Text

default

Credentials INI default profile section variable.

credFile :: (MonadCatch m, MonadIO m) => m FilePath Source #

Default path for the credentials file. This looks in in the HOME directory as determined by the directory library.

  • UNIXOSX: @$HOME.aws/credentials@
  • Windows: C:/Users//<user>.awscredentials

Note: This does not match the default AWS SDK location of %USERPROFILE%.awscredentials on Windows. (Sorry.)

Credentials

getAuth is implemented using the following from*-styled functions below. Both fromKeys and fromSession can be used directly to avoid the MonadIO constraint.

fromKeys :: AccessKey -> SecretKey -> Auth Source #

Explicit access and secret keys.

fromSession :: AccessKey -> SecretKey -> SessionToken -> Auth Source #

Temporary credentials from a STS session consisting of the access key, secret key, and session token.

See: fromTemporarySession

fromTemporarySession :: AccessKey -> SecretKey -> SessionToken -> UTCTime -> Auth Source #

Temporary credentials from a STS session consisting of the access key, secret key, session token, and expiration time.

See: fromSession

fromEnv :: (Applicative m, MonadIO m, MonadThrow m) => m (Auth, Maybe Region) Source #

Retrieve access key, secret key, and a session token from the default environment variables.

Throws MissingEnvError if either of the default environment variables cannot be read, but not if the session token is absent.

See: envAccessKey, envSecretKey, envSessionToken

fromEnvKeys Source #

Arguments

:: (Applicative m, MonadIO m, MonadThrow m) 
=> Text

Access key environment variable.

-> Text

Secret key environment variable.

-> Maybe Text

Session token environment variable.

-> Maybe Text

Region environment variable.

-> m (Auth, Maybe Region) 

Retrieve access key, secret key and a session token from specific environment variables.

Throws MissingEnvError if either of the specified key environment variables cannot be read, but not if the session token is absent.

fromFile :: (Applicative m, MonadIO m, MonadCatch m) => m (Auth, Maybe Region) Source #

Loads the default credentials INI file using the default profile name.

Throws MissingFileError if credFile is missing, or InvalidFileError if an error occurs during parsing.

See: credProfile, credFile, and envProfile

fromFilePath :: (Applicative m, MonadIO m, MonadCatch m) => Text -> FilePath -> m (Auth, Maybe Region) Source #

Retrieve the access, secret and session token from the specified section (profile) in a valid INI credentials file.

Throws MissingFileError if the specified file is missing, or InvalidFileError if an error occurs during parsing.

fromProfile :: (MonadIO m, MonadCatch m) => Manager -> m (Auth, Maybe Region) Source #

Retrieve the default IAM Profile from the local EC2 instance-data.

The default IAM profile is determined by Amazon as the first profile found in the response from: http://169.254.169.254/latest/meta-data/iam/security-credentials/

Throws RetrievalError if the HTTP call fails, or InvalidIAMError if the default IAM profile cannot be read.

fromProfileName :: (MonadIO m, MonadCatch m) => Manager -> Text -> m (Auth, Maybe Region) Source #

Lookup a specific IAM Profile by name from the local EC2 instance-data.

Additionally starts a refresh thread for the given authentication environment.

The resulting IORef wrapper + timer is designed so that multiple concurrent accesses of AuthEnv from the AWS environment are not required to calculate expiry and sequentially queue to update it.

The forked timer ensures a singular owner and pre-emptive refresh of the temporary session credentials before expiration.

A weak reference is used to ensure that the forked thread will eventually terminate when Auth is no longer referenced.

If no session token or expiration time is present the credentials will be returned verbatim.

fromContainer :: (MonadIO m, MonadThrow m) => Manager -> m (Auth, Maybe Region) Source #

Obtain credentials exposed to a task via the ECS container agent, as described in the IAM Roles for Tasks section of the AWS ECS documentation. The credentials are obtained by making a request to http://169.254.170.2 at the path contained by the envContainerCredentialsURI environment variable.

The ECS container agent provides an access key, secret key, session token, and expiration time, but it does not include a region, so the region will attempt to be determined from the envRegion environment variable if it is set.

Like fromProfileName, additionally starts a refresh thread that will periodically fetch fresh credentials before the current ones expire.

Throws MissingEnvError if the envContainerCredentialsURI environment variable is not set or InvalidIAMError if the payload returned by the ECS container agent is not of the expected format.

Keys

newtype AccessKey :: * #

An access key ID.

For example: AKIAIOSFODNN7EXAMPLE

See: Understanding and Getting Your Security Credentials.

Constructors

AccessKey ByteString 

Instances

Eq AccessKey 
Data AccessKey 

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> AccessKey -> c AccessKey #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c AccessKey #

toConstr :: AccessKey -> Constr #

dataTypeOf :: AccessKey -> DataType #

dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c AccessKey) #

dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c AccessKey) #

gmapT :: (forall b. Data b => b -> b) -> AccessKey -> AccessKey #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> AccessKey -> r #

gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> AccessKey -> r #

gmapQ :: (forall d. Data d => d -> u) -> AccessKey -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> AccessKey -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> AccessKey -> m AccessKey #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> AccessKey -> m AccessKey #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> AccessKey -> m AccessKey #

Read AccessKey 
Show AccessKey 
IsString AccessKey 
Hashable AccessKey 
FromJSON AccessKey 
ToJSON AccessKey 
NFData AccessKey 

Methods

rnf :: AccessKey -> () #

FromXML AccessKey 
ToXML AccessKey 

Methods

toXML :: AccessKey -> XML #

ToLog AccessKey 

Methods

build :: AccessKey -> Builder #

ToQuery AccessKey 
ToByteString AccessKey 

Methods

toBS :: AccessKey -> ByteString #

FromText AccessKey 
ToText AccessKey 

Methods

toText :: AccessKey -> Text #

newtype SecretKey :: * #

Secret access key credential.

For example: wJalrXUtnFEMIK7MDENGbPxRfiCYEXAMPLEKE

See: Understanding and Getting Your Security Credentials.

Constructors

SecretKey ByteString 

Instances

Eq SecretKey 
Data SecretKey 

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> SecretKey -> c SecretKey #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c SecretKey #

toConstr :: SecretKey -> Constr #

dataTypeOf :: SecretKey -> DataType #

dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c SecretKey) #

dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c SecretKey) #

gmapT :: (forall b. Data b => b -> b) -> SecretKey -> SecretKey #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> SecretKey -> r #

gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> SecretKey -> r #

gmapQ :: (forall d. Data d => d -> u) -> SecretKey -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> SecretKey -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> SecretKey -> m SecretKey #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> SecretKey -> m SecretKey #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> SecretKey -> m SecretKey #

IsString SecretKey 
Hashable SecretKey 
FromJSON SecretKey 
ToJSON SecretKey 
NFData SecretKey 

Methods

rnf :: SecretKey -> () #

FromXML SecretKey 
ToXML SecretKey 

Methods

toXML :: SecretKey -> XML #

ToByteString SecretKey 

Methods

toBS :: SecretKey -> ByteString #

FromText SecretKey 
ToText SecretKey 

Methods

toText :: SecretKey -> Text #

newtype SessionToken :: * #

A session token used by STS to temporarily authorise access to an AWS resource.

See: Temporary Security Credentials.

Constructors

SessionToken ByteString 

Instances

Eq SessionToken 
Data SessionToken 

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> SessionToken -> c SessionToken #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c SessionToken #

toConstr :: SessionToken -> Constr #

dataTypeOf :: SessionToken -> DataType #

dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c SessionToken) #

dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c SessionToken) #

gmapT :: (forall b. Data b => b -> b) -> SessionToken -> SessionToken #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> SessionToken -> r #

gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> SessionToken -> r #

gmapQ :: (forall d. Data d => d -> u) -> SessionToken -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> SessionToken -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> SessionToken -> m SessionToken #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> SessionToken -> m SessionToken #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> SessionToken -> m SessionToken #

IsString SessionToken 
Hashable SessionToken 
FromJSON SessionToken 
ToJSON SessionToken 
NFData SessionToken 

Methods

rnf :: SessionToken -> () #

FromXML SessionToken 
ToXML SessionToken 

Methods

toXML :: SessionToken -> XML #

ToByteString SessionToken 
FromText SessionToken 
ToText SessionToken 

Methods

toText :: SessionToken -> Text #

Handling Errors

class AsAuthError a where Source #

Minimal complete definition

_AuthError

Methods

_AuthError :: Prism' a AuthError Source #

A general authentication error.

_RetrievalError :: Prism' a HttpException Source #

An error occured while communicating over HTTP with the local metadata endpoint.

_MissingEnvError :: Prism' a Text Source #

The named environment variable was not found.

_InvalidEnvError :: Prism' a Text Source #

An error occured parsing named environment variable's value.

_MissingFileError :: Prism' a FilePath Source #

The specified credentials file could not be found.

_InvalidFileError :: Prism' a Text Source #

An error occured parsing the credentials file.

_InvalidIAMError :: Prism' a Text Source #

The specified IAM profile could not be found or deserialised.