Skip to content

Commit 6d72b23

Browse files
committed
Remove the replaced credentials providers
Remove ProcessCredentialsProvider and the original ProfileConfigFileAWSCredentialsProvider. The default chain stopped using them once the CRT-backed ProfileCredentialsProvider took over their work, and with the account ID and AWS_DEFAULT_PROFILE fixes it now covers what they did, apart from re-reading the files on refreshRateMs. ProfileConfigFileAWSCredentialsProvider stays as a deprecated alias of ProfileCredentialsProvider. GetCredentialsFromProcess stays, since STSProfileCredentialsProvider uses it. Drop the GeneralHTTPCredentialsProvider.h include that AWSCredentialsProvider.h kept for 1.11 compatibility. Move the tests to ProfileCredentialsProvider: remove leading whitespace that the shared config format reads as a continuation line, drop the reload check and the ProcessCredentialsProvider tests, and point the credential_process tests at an empty credentials file so a local [default] can't take over.
1 parent e93217a commit 6d72b23

11 files changed

Lines changed: 181 additions & 396 deletions
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"type": "breaking-change",
3+
"category": "aws-cpp-sdk-core",
4+
"contributor": "averyk22",
5+
"description": "Remove ProcessCredentialsProvider and the original ProfileConfigFileAWSCredentialsProvider, which the default chain stopped using once the CRT-backed ProfileCredentialsProvider took over their work. ProfileConfigFileAWSCredentialsProvider still compiles as a deprecated alias of ProfileCredentialsProvider; use ProfileCredentialsProvider for credential_process too. ProfileCredentialsProvider's default constructor picks the profile from AWS_PROFILE, then default; unlike the old provider, it does not read AWS_DEFAULT_PROFILE, and an empty AWS_PROFILE is not treated as default, so set it to a profile name or unset it. Unlike the old provider, ProfileCredentialsProvider reads the config and credentials files once when it is created, so keys rotated in the files are picked up only by a new provider. It also follows the shared config file format strictly: a line that starts with whitespace continues the previous property, so a profile line indented by mistake can stop the file from loading. AWSCredentialsProvider.h no longer includes GeneralHTTPCredentialsProvider.h; include it directly to use GeneralHTTPCredentialsProvider or TaskRoleCredentialsProvider."
6+
}

‎src/aws-cpp-sdk-core/include/aws/core/auth/AWSCredentialsProvider.h‎

Lines changed: 1 addition & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -146,58 +146,6 @@ namespace Aws
146146
AWSCredentials GetAWSCredentials() override;
147147
};
148148

149-
/**
150-
* Reads credentials profile from the default Profile Config File. Refreshes at set interval for credential rotation.
151-
* Looks for environment variables AWS_SHARED_CREDENTIALS_FILE and AWS_PROFILE. If they aren't found, then it defaults
152-
* to the default profile in ~/.aws/credentials.
153-
* Optionally a user can specify the profile and it will override the environment variable
154-
* and defaults. To alter the file this pulls from, then the user should alter the AWS_SHARED_CREDENTIALS_FILE variable.
155-
*/
156-
// class AWS_DEPRECATED("This class is in the maintenance mode, no new updates will be released, use S3EncryptionClientV3. Please see https://docs.aws.amazon.com/general/latest/gr/aws_sdk_cryptography.html for more information.") AWS_CORE_API ProfileConfigFileAWSCredentialsProvider : public AWSCredentialsProvider
157-
class AWS_CORE_API ProfileConfigFileAWSCredentialsProvider : public AWSCredentialsProvider
158-
{
159-
public:
160-
161-
/**
162-
* Initializes with refreshRateMs as the frequency at which the file is reparsed in milliseconds. Defaults to 5 minutes.
163-
*/
164-
ProfileConfigFileAWSCredentialsProvider(long refreshRateMs = REFRESH_THRESHOLD);
165-
166-
/**
167-
* Initializes with a profile override and
168-
* refreshRateMs as the frequency at which the file is reparsed in milliseconds. Defaults to 5 minutes.
169-
*/
170-
ProfileConfigFileAWSCredentialsProvider(const char* profile, long refreshRateMs = REFRESH_THRESHOLD);
171-
172-
/**
173-
* Retrieves the credentials if found, otherwise returns empty credential set.
174-
*/
175-
AWSCredentials GetAWSCredentials() override;
176-
177-
/**
178-
* Returns the fullpath of the calculated credentials profile file
179-
*/
180-
static Aws::String GetCredentialsProfileFilename();
181-
182-
/**
183-
* Returns the directory storing the profile file.
184-
*/
185-
static Aws::String GetProfileDirectory();
186-
187-
protected:
188-
void Reload() override;
189-
private:
190-
191-
/**
192-
* Checks to see if the refresh interval has expired and reparses the file if it has.
193-
*/
194-
void RefreshIfExpired();
195-
196-
Aws::String m_profileToUse;
197-
Aws::Config::AWSConfigFileProfileConfigLoader m_credentialsFileLoader;
198-
long m_loadFrequencyMs;
199-
};
200-
201149
/**
202150
* Credentials provider implementation that loads credentials from the Amazon
203151
* EC2 Instance Metadata Service.
@@ -237,51 +185,7 @@ namespace Aws
237185
std::shared_ptr<Aws::Config::AWSProfileConfigLoader> m_ec2MetadataConfigLoader;
238186
long m_loadFrequencyMs;
239187
};
240-
241-
/**
242-
* Process credentials provider that loads credentials by running another command (or program) configured in config file
243-
* The configuration format is as following:
244-
* credential_process = command_path <arguments_list>
245-
* Each time the credentials needs to be refreshed, this command will be executed with configured arguments.
246-
* The default profile name to look up this configuration is "default", same as normal aws credentials configuration and other configurations.
247-
* The expected valid output of the command is a Json doc output to stdout:
248-
* {"Version": 1, "AccessKeyId": "AccessKey123", "SecretAccessKey": "SecretKey321", "SessionToken": "Token123", "Expiration": "1970-01-01T00:00:01Z"}
249-
* The Version key specifies the version of the JSON payload and must be set to 1 for now (as an integer type).
250-
* If the Version key is bumped to 2, SDKs would support both versions of the returned payload.
251-
* Value of Expiration field should be an valid ISO8601 formatted date string as above example.
252-
* The expected error message of the command is a string to output to stderr.
253-
*/
254-
class AWS_CORE_API ProcessCredentialsProvider : public AWSCredentialsProvider
255-
{
256-
public:
257-
/**
258-
* Initializes the provider by checking default profile
259-
*/
260-
ProcessCredentialsProvider();
261-
262-
/**
263-
* Initializes the provider by checking specified profile
264-
* @param profile which profile in config file to use.
265-
*/
266-
ProcessCredentialsProvider(const Aws::String& profile);
267-
268-
/**
269-
* Retrieves the credentials if found, otherwise returns empty credential set.
270-
*/
271-
AWSCredentials GetAWSCredentials() override;
272-
273-
protected:
274-
void Reload() override;
275-
private:
276-
void RefreshIfExpired();
277-
278-
private:
279-
Aws::String m_profileToUse;
280-
Aws::Auth::AWSCredentials m_credentials;
281-
};
282188
} // namespace Auth
283189
} // namespace Aws
284190

285-
// TODO: remove on a next minor API bump from 1.11.x
286-
#endif // !defined(AWS_CLIENT_H)
287-
#include <aws/core/auth/GeneralHTTPCredentialsProvider.h>
191+
#endif // !defined(AWS_CREDENTIALS_PROVIDER)

‎src/aws-cpp-sdk-core/include/aws/core/auth/AWSCredentialsProviderChain.h‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,15 @@ namespace Aws
5353
};
5454

5555
/**
56-
* Creates an AWSCredentialsProviderChain which uses in order EnvironmentAWSCredentialsProvider, ProfileConfigFileAWSCredentialsProvider,
57-
* ProcessCredentialsProvider, STSAssumeRoleWebIdentityCredentialsProvider and SSOCredentialsProvider.
56+
* Creates an AWSCredentialsProviderChain which uses in order EnvironmentAWSCredentialsProvider, ProfileCredentialsProvider,
57+
* STSAssumeRoleWebIdentityCredentialsProvider and SSOCredentialsProvider.
5858
*/
5959
class AWS_CORE_API DefaultAWSCredentialsProviderChain : public AWSCredentialsProviderChain
6060
{
6161
public:
6262
/**
63-
* Initializes the provider chain with EnvironmentAWSCredentialsProvider, ProfileConfigFileAWSCredentialsProvider,
64-
* ProcessCredentialsProvider, STSAssumeRoleWebIdentityCredentialsProvider and SSOCredentialsProvider in that order.
63+
* Initializes the provider chain with EnvironmentAWSCredentialsProvider, ProfileCredentialsProvider,
64+
* STSAssumeRoleWebIdentityCredentialsProvider and SSOCredentialsProvider in that order.
6565
*/
6666
DefaultAWSCredentialsProviderChain();
6767

‎src/aws-cpp-sdk-core/include/aws/core/auth/ProfileCredentialsProvider.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,7 @@ class AWS_CORE_API ProfileCredentialsProvider : public AWSCredentialsProvider {
5757
class ProfileCredentialsProviderImp;
5858
std::shared_ptr<ProfileCredentialsProviderImp> m_impl;
5959
};
60+
61+
using ProfileConfigFileAWSCredentialsProvider [[deprecated("Use ProfileCredentialsProvider")]] = ProfileCredentialsProvider;
6062
} // namespace Auth
6163
} // namespace Aws

‎src/aws-cpp-sdk-core/source/auth/AWSCredentialsProvider.cpp‎

Lines changed: 0 additions & 146 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,9 @@ static const char DEFAULT_PROFILE[] = "default";
4343
static const char AWS_PROFILE_ENV_VAR[] = "AWS_PROFILE";
4444
static const char AWS_PROFILE_DEFAULT_ENV_VAR[] = "AWS_DEFAULT_PROFILE";
4545

46-
static const char AWS_CREDENTIALS_FILE[] = "AWS_SHARED_CREDENTIALS_FILE";
4746
extern const char AWS_CONFIG_FILE[] = "AWS_CONFIG_FILE";
4847

4948
extern const char PROFILE_DIRECTORY[] = ".aws";
50-
static const char DEFAULT_CREDENTIALS_FILE[] = "credentials";
5149
extern const char DEFAULT_CONFIG_FILE[] = "config";
5250

5351

@@ -144,97 +142,6 @@ Aws::String Aws::Auth::GetConfigProfileName()
144142

145143
static const char* PROFILE_LOG_TAG = "ProfileConfigFileAWSCredentialsProvider";
146144

147-
Aws::String ProfileConfigFileAWSCredentialsProvider::GetCredentialsProfileFilename()
148-
{
149-
auto credentialsFileNameFromVar = Aws::Environment::GetEnv(AWS_CREDENTIALS_FILE);
150-
151-
if (credentialsFileNameFromVar.empty())
152-
{
153-
return Aws::FileSystem::GetHomeDirectory() + PROFILE_DIRECTORY + PATH_DELIM + DEFAULT_CREDENTIALS_FILE;
154-
}
155-
else
156-
{
157-
return credentialsFileNameFromVar;
158-
}
159-
}
160-
161-
Aws::String ProfileConfigFileAWSCredentialsProvider::GetProfileDirectory()
162-
{
163-
Aws::String credentialsFileName = GetCredentialsProfileFilename();
164-
auto lastSeparator = credentialsFileName.find_last_of(PATH_DELIM);
165-
if (lastSeparator != std::string::npos)
166-
{
167-
return credentialsFileName.substr(0, lastSeparator);
168-
}
169-
else
170-
{
171-
return {};
172-
}
173-
}
174-
175-
ProfileConfigFileAWSCredentialsProvider::ProfileConfigFileAWSCredentialsProvider(long refreshRateMs) :
176-
m_profileToUse(Aws::Auth::GetConfigProfileName()),
177-
m_credentialsFileLoader(GetCredentialsProfileFilename()),
178-
m_loadFrequencyMs(refreshRateMs)
179-
{
180-
AWS_LOGSTREAM_INFO(PROFILE_LOG_TAG, "Setting provider to read credentials from " << GetCredentialsProfileFilename() << " for credentials file"
181-
<< " and " << GetConfigProfileFilename() << " for the config file "
182-
<< ", for use with profile " << m_profileToUse);
183-
}
184-
185-
ProfileConfigFileAWSCredentialsProvider::ProfileConfigFileAWSCredentialsProvider(const char* profile, long refreshRateMs) :
186-
m_profileToUse(profile),
187-
m_credentialsFileLoader(GetCredentialsProfileFilename()),
188-
m_loadFrequencyMs(refreshRateMs)
189-
{
190-
AWS_LOGSTREAM_INFO(PROFILE_LOG_TAG, "Setting provider to read credentials from " << GetCredentialsProfileFilename() << " for credentials file"
191-
<< " and " << GetConfigProfileFilename() << " for the config file "
192-
<< ", for use with profile " << m_profileToUse);
193-
}
194-
195-
AWSCredentials ProfileConfigFileAWSCredentialsProvider::GetAWSCredentials()
196-
{
197-
RefreshIfExpired();
198-
ReaderLockGuard guard(m_reloadLock);
199-
const Aws::Map<Aws::String, Aws::Config::Profile>& profiles = m_credentialsFileLoader.GetProfiles();
200-
auto credsFileProfileIter = profiles.find(m_profileToUse);
201-
202-
if(credsFileProfileIter != profiles.end())
203-
{
204-
AWSCredentials credentials = credsFileProfileIter->second.GetCredentials();
205-
if (!credentials.IsEmpty()) {
206-
credentials.AddUserAgentFeature(UserAgentFeature::CREDENTIALS_PROFILE);
207-
}
208-
return credentials;
209-
}
210-
211-
return AWSCredentials();
212-
}
213-
214-
215-
void ProfileConfigFileAWSCredentialsProvider::Reload()
216-
{
217-
m_credentialsFileLoader.Load();
218-
AWSCredentialsProvider::Reload();
219-
}
220-
221-
void ProfileConfigFileAWSCredentialsProvider::RefreshIfExpired()
222-
{
223-
ReaderLockGuard guard(m_reloadLock);
224-
if (!IsTimeToRefresh(m_loadFrequencyMs))
225-
{
226-
return;
227-
}
228-
229-
guard.UpgradeToWriterLock();
230-
if (!IsTimeToRefresh(m_loadFrequencyMs)) // double-checked lock to avoid refreshing twice
231-
{
232-
return;
233-
}
234-
235-
Reload();
236-
}
237-
238145
static const char* INSTANCE_LOG_TAG = "InstanceProfileCredentialsProvider";
239146

240147
InstanceProfileCredentialsProvider::InstanceProfileCredentialsProvider(long refreshRateMs) :
@@ -334,59 +241,6 @@ void InstanceProfileCredentialsProvider::RefreshIfExpired()
334241
Reload();
335242
}
336243

337-
static const char PROCESS_LOG_TAG[] = "ProcessCredentialsProvider";
338-
ProcessCredentialsProvider::ProcessCredentialsProvider() :
339-
m_profileToUse(Aws::Auth::GetConfigProfileName())
340-
{
341-
AWS_LOGSTREAM_INFO(PROCESS_LOG_TAG, "Setting process credentials provider to read config from " << m_profileToUse);
342-
}
343-
344-
ProcessCredentialsProvider::ProcessCredentialsProvider(const Aws::String& profile) :
345-
m_profileToUse(profile)
346-
{
347-
AWS_LOGSTREAM_INFO(PROCESS_LOG_TAG, "Setting process credentials provider to read config from " << m_profileToUse);
348-
}
349-
350-
AWSCredentials ProcessCredentialsProvider::GetAWSCredentials()
351-
{
352-
RefreshIfExpired();
353-
ReaderLockGuard guard(m_reloadLock);
354-
return m_credentials;
355-
}
356-
357-
358-
void ProcessCredentialsProvider::Reload()
359-
{
360-
auto profile = Aws::Config::GetCachedConfigProfile(m_profileToUse);
361-
const Aws::String &command = profile.GetCredentialProcess();
362-
if (command.empty())
363-
{
364-
AWS_LOGSTREAM_INFO(PROCESS_LOG_TAG, "Failed to find credential process's profile: " << m_profileToUse);
365-
return;
366-
}
367-
m_credentials = GetCredentialsFromProcess(command);
368-
if (!m_credentials.IsEmpty()) {
369-
m_credentials.AddUserAgentFeature(UserAgentFeature::CREDENTIALS_PROFILE_PROCESS);
370-
}
371-
}
372-
373-
void ProcessCredentialsProvider::RefreshIfExpired()
374-
{
375-
ReaderLockGuard guard(m_reloadLock);
376-
if (!m_credentials.IsExpiredOrEmpty())
377-
{
378-
return;
379-
}
380-
381-
guard.UpgradeToWriterLock();
382-
if (!m_credentials.IsExpiredOrEmpty()) // double-checked lock to avoid refreshing twice
383-
{
384-
return;
385-
}
386-
387-
Reload();
388-
}
389-
390244
AWSCredentials Aws::Auth::GetCredentialsFromProcess(const Aws::String& process)
391245
{
392246
Aws::String command = process;

‎src/aws-cpp-sdk-core/source/auth/AWSCredentialsProviderChain.cpp‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
#include <aws/core/auth/AWSCredentialsProviderChain.h>
7+
#include <aws/core/auth/GeneralHTTPCredentialsProvider.h>
78
#include <aws/core/auth/LoginCredentialsProvider.h>
89
#include <aws/core/auth/SSOCredentialsProvider.h>
910
#include <aws/core/auth/STSCredentialsProvider.h>

0 commit comments

Comments
 (0)