-
Notifications
You must be signed in to change notification settings - Fork 149
Check for connection strings and managed identity settings on deployment #4423
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6c54100
Detect local/remote connection settings
nturinski 88ffa9c
Detect local/remote connection settings
nturinski dc543aa
Merge from main
nturinski aaaf73b
Warn users about connection strings/mi usage
nturinski 7fb4374
Remove comment
nturinski ff7a4ce
Merge branch 'main' of https://github.com/microsoft/vscode-azurefunct…
nturinski 13209d5
Update appservice package
nturinski 9ac5b04
Merge main
nturinski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| /*--------------------------------------------------------------------------------------------- | ||
| * Copyright (c) Microsoft Corporation. All rights reserved. | ||
| * Licensed under the MIT License. See License.txt in the project root for license information. | ||
| *--------------------------------------------------------------------------------------------*/ | ||
|
|
||
| import { type StringDictionary } from "@azure/arm-appservice"; | ||
| import { isSettingConvertible } from '@microsoft/vscode-azext-azureappsettings'; | ||
| import { AzExtFsExtra, type IActionContext } from "@microsoft/vscode-azext-utils"; | ||
| import { localEventHubsEmulatorConnectionRegExp, localStorageEmulatorConnectionString } from "../../constants"; | ||
| import { type ILocalSettingsJson } from "../../funcConfig/local.settings"; | ||
| import { localize } from "../../localize"; | ||
| import { type SlotTreeItem } from "../../tree/SlotTreeItem"; | ||
| import { tryGetLocalSettingsFileNoPrompt } from "../appSettings/localSettings/getLocalSettingsFile"; | ||
|
|
||
| type ConnectionSetting = { name: string, value: string, type: 'ConnectionString' | 'ManagedIdentity' | 'Emulator' }; | ||
|
|
||
| export async function getWarningsForConnectionSettings(context: IActionContext, | ||
| options: { | ||
| appSettings: StringDictionary, | ||
| node: SlotTreeItem, | ||
| projectPath: string | undefined | ||
| }): Promise<string | undefined> { | ||
|
|
||
| const localSettingsPath = await tryGetLocalSettingsFileNoPrompt(context, options.projectPath); | ||
| const localSettings: ILocalSettingsJson = localSettingsPath ? await AzExtFsExtra.readJSON(localSettingsPath) : { Values: {} }; | ||
| const localConnectionSettings = await getConnectionSettings(localSettings.Values ?? {}); | ||
| const remoteConnectionSettings = await getConnectionSettings(options.appSettings?.properties ?? {}); | ||
|
|
||
| if (localConnectionSettings.some(setting => setting.type === 'ManagedIdentity')) { | ||
| if (!options.node.site.rawSite.identity || | ||
| options.node.site.rawSite.identity.type === 'None') { | ||
| // if they have nothing in remote, warn them to connect a managed identity | ||
| return localize('configureManagedIdentityWarning', | ||
| 'Your app is not connected to a managed identity. To ensure access, please configure a managed identity. Without it, your application may encounter authorization issues.'); | ||
| } | ||
| } | ||
|
|
||
| if (localConnectionSettings.some(setting => setting.type === 'ConnectionString') || remoteConnectionSettings.some(setting => setting.type === 'ConnectionString')) { | ||
| // if they have connection strings, warn them about insecure connections but don't try to convert them | ||
| return localize('connectionStringWarning', | ||
| 'Your app may be using connection strings for authentication. This may expose sensitive credentials and lead to security vulnerabilities. Consider using managed identities to enhance security.') | ||
| } | ||
|
|
||
| return; | ||
| } | ||
|
|
||
| function checkForConnectionSettings(property: { [propertyName: string]: string }): ConnectionSetting | undefined { | ||
| if (isSettingConvertible(property.propertyName, property.value)) { | ||
| // if the setting is convertible, we can assume it's a connection string | ||
| return { | ||
| name: property.propertyName, | ||
| value: property.value, | ||
| type: 'ConnectionString' | ||
| }; | ||
| } | ||
|
|
||
| return undefined; | ||
| } | ||
| function checkForManagedIdentitySettings(property: { [propertyName: string]: string }): ConnectionSetting | undefined { | ||
|
|
||
| if (property.propertyName.includes('__accountName') || property.propertyName.includes('__blobServiceUri') || | ||
| property.propertyName.includes('__queueServiceUri') || property.propertyName.includes('__tableServiceUri') || | ||
| property.propertyName.includes('__accountEndpoint') || property.propertyName.includes('__fullyQualifiedNamespace')) { | ||
| return { | ||
| name: property.propertyName, | ||
| value: property.value, | ||
| type: 'ManagedIdentity' | ||
| }; | ||
| } | ||
|
|
||
| return undefined; | ||
| } | ||
|
|
||
| function checkForEmulatorSettings(property: { [propertyName: string]: string }): ConnectionSetting | undefined { | ||
| if (property.value.includes(localStorageEmulatorConnectionString) || | ||
| localEventHubsEmulatorConnectionRegExp.test(property.value)) { | ||
| return { | ||
| name: property.propertyName, | ||
| value: property.value, | ||
| type: 'Emulator' | ||
| }; | ||
| } | ||
|
|
||
| return undefined; | ||
| } | ||
|
|
||
| async function getConnectionSettings(properties: StringDictionary): Promise<ConnectionSetting[]> { | ||
| const settings: ConnectionSetting[] = []; | ||
| for (const [key, value] of Object.entries(properties)) { | ||
| const property = { propertyName: key, value: value as string }; | ||
| const connectionSetting = checkForManagedIdentitySettings(property) ?? checkForConnectionSettings(property) ?? checkForEmulatorSettings(property); | ||
| if (connectionSetting) { | ||
| settings.push(connectionSetting); | ||
| } | ||
| } | ||
|
|
||
| return settings; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the future, if we need to add more emulator strings, we'll have to remember to update them here as well. I'm wondering if it might be more foolproof to create a centralized list of emulator strings as part of our constants and then loop over that list instead to perform the checks. This way, we would only need to maintain the single list at the centralized location. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that's a good idea.