Skip to content

Commit 1e8c9d0

Browse files
authored
Prepare for the June Identity GA release. (#5695)
* Prepare for the June Identity GA release. * Validate azure arc. * Update changelog entry. * Update cspell, fixup gtest skip, and remove unnecessary logging. * Move gtest_skip call inside the gtest. * Use system command due to permissions on creating a directory, on linux. * Pass in a c_str() to system. * Update permissions to create keys and address pr feedback (rename test var and method to remove 'valid'). * Address PR feedback - nits. * Fix remaining rename of local variable.
1 parent 4ca2c8f commit 1e8c9d0

File tree

5 files changed

+398
-12
lines changed

5 files changed

+398
-12
lines changed

.vscode/cspell.json

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
"authcid",
7171
"avro",
7272
"antkmsft",
73+
"azcmagent",
7374
"azcore",
7475
"azsdk",
7576
"azsdkengsys",

sdk/identity/azure-identity/CHANGELOG.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
# Release History
22

3-
## 1.7.0-beta.3 (Unreleased)
3+
## 1.8.0 (2024-06-11)
44

55
### Features Added
66

7-
### Breaking Changes
7+
- [[#4474]](https://github.com/Azure/azure-sdk-for-cpp/issues/4474) Enable proactive renewal of Managed Identity tokens.
8+
- [[#5116]](https://github.com/Azure/azure-sdk-for-cpp/issues/5116) `AzureCliCredential`: Added support for the new response field which represents token expiration timestamp as time zone agnostic value.
89

910
### Bugs Fixed
1011

11-
### Other Changes
12+
- Managed identity bug fixes.
1213

1314
## 1.7.0-beta.2 (2024-02-09)
1415

sdk/identity/azure-identity/src/managed_identity_source.cpp

+75-1
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@
66
#include "private/identity_log.hpp"
77

88
#include <azure/core/internal/environment.hpp>
9+
#include <azure/core/platform.hpp>
910

1011
#include <fstream>
1112
#include <iterator>
1213
#include <stdexcept>
1314
#include <utility>
1415

16+
#include <sys/stat.h> // for stat() used to check file size
17+
1518
using namespace Azure::Identity::_detail;
1619

1720
using Azure::Core::_internal::Environment;
@@ -30,6 +33,73 @@ void PrintEnvNotSetUpMessage(std::string const& credName, std::string const& cre
3033
credName + ": Environment is not set up for the credential to be created"
3134
+ WithSourceMessage(credSource) + '.');
3235
}
36+
37+
// ExpectedArcKeyDirectory returns the directory expected to contain Azure Arc keys.
38+
std::string ExpectedArcKeyDirectory()
39+
{
40+
using Azure::Core::Credentials::AuthenticationException;
41+
42+
#if defined(AZ_PLATFORM_LINUX)
43+
return "/var/opt/azcmagent/tokens";
44+
#elif defined(AZ_PLATFORM_WINDOWS)
45+
const std::string programDataPath{
46+
Azure::Core::_internal::Environment::GetVariable("ProgramData")};
47+
if (programDataPath.empty())
48+
{
49+
throw AuthenticationException("Unable to get ProgramData folder path.");
50+
}
51+
return programDataPath + "\\AzureConnectedMachineAgent\\Tokens";
52+
#else
53+
throw AuthenticationException("Unsupported OS. Arc supports only Linux and Windows.");
54+
#endif
55+
}
56+
57+
static constexpr off_t MaximumAzureArcKeySize = 4096;
58+
59+
#if defined(AZ_PLATFORM_WINDOWS)
60+
static constexpr char DirectorySeparator = '\\';
61+
#else
62+
static constexpr char DirectorySeparator = '/';
63+
#endif
64+
65+
// Validates that a given Azure Arc MSI file path is valid for use.
66+
// The specified file must:
67+
// - be in the expected directory for the OS
68+
// - have a .key extension
69+
// - contain at most 4096 bytes
70+
void ValidateArcKeyFile(std::string fileName)
71+
{
72+
using Azure::Core::Credentials::AuthenticationException;
73+
74+
std::string directory;
75+
const size_t lastSlashIndex = fileName.rfind(DirectorySeparator);
76+
if (std::string::npos != lastSlashIndex)
77+
{
78+
directory = fileName.substr(0, lastSlashIndex);
79+
}
80+
if (directory != ExpectedArcKeyDirectory() || fileName.size() < 5
81+
|| fileName.substr(fileName.size() - 4) != ".key")
82+
{
83+
throw AuthenticationException(
84+
"The file specified in the 'WWW-Authenticate' header in the response from Azure Arc "
85+
"Managed Identity Endpoint has an unexpected file path.");
86+
}
87+
88+
struct stat s;
89+
if (!stat(fileName.c_str(), &s))
90+
{
91+
if (s.st_size > MaximumAzureArcKeySize)
92+
{
93+
throw AuthenticationException(
94+
"The file specified in the 'WWW-Authenticate' header in the response from Azure Arc "
95+
"Managed Identity Endpoint is larger than 4096 bytes.");
96+
}
97+
}
98+
else
99+
{
100+
throw AuthenticationException("Failed to get file size for '" + fileName + "'.");
101+
}
102+
}
33103
} // namespace
34104

35105
Azure::Core::Url ManagedIdentitySource::ParseEndpointUrl(
@@ -352,7 +422,11 @@ Azure::Core::Credentials::AccessToken AzureArcManagedIdentitySource::GetToken(
352422
}
353423

354424
auto request = createRequest();
355-
std::ifstream secretFile(challenge.substr(eq + 1));
425+
426+
const std::string fileName = challenge.substr(eq + 1);
427+
ValidateArcKeyFile(fileName);
428+
429+
std::ifstream secretFile(fileName);
356430
request->HttpRequest.SetHeader(
357431
"Authorization",
358432
"Basic "

sdk/identity/azure-identity/src/private/package_version.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
#include <cstdint>
1212

1313
#define AZURE_IDENTITY_VERSION_MAJOR 1
14-
#define AZURE_IDENTITY_VERSION_MINOR 7
14+
#define AZURE_IDENTITY_VERSION_MINOR 8
1515
#define AZURE_IDENTITY_VERSION_PATCH 0
16-
#define AZURE_IDENTITY_VERSION_PRERELEASE "beta.3"
16+
#define AZURE_IDENTITY_VERSION_PRERELEASE ""
1717

1818
#define AZURE_IDENTITY_VERSION_ITOA_HELPER(i) #i
1919
#define AZURE_IDENTITY_VERSION_ITOA(i) AZURE_IDENTITY_VERSION_ITOA_HELPER(i)

0 commit comments

Comments
 (0)