Skip to content
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

mgmt, support convenience API for publicNetworkAccess in Vault #39309

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@

### Features Added

### Breaking Changes

### Bugs Fixed

### Other Changes
- Supported disabling public network access in `Vault` via `disablePublicNetworkAccess()`, for private link feature.

## 2.36.0 (2024-02-29)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "java",
"TagPrefix": "java/resourcemanager/azure-resourcemanager-keyvault",
"Tag": "java/resourcemanager/azure-resourcemanager-keyvault_a24b8fea25"
"Tag": "java/resourcemanager/azure-resourcemanager-keyvault_1a7324e6c1"
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.azure.resourcemanager.keyvault.models.NetworkRuleSet;
import com.azure.resourcemanager.keyvault.models.PrivateEndpointServiceConnectionStatus;
import com.azure.resourcemanager.keyvault.models.PrivateLinkServiceConnectionState;
import com.azure.resourcemanager.keyvault.models.PublicNetworkAccess;
import com.azure.resourcemanager.keyvault.models.Secrets;
import com.azure.resourcemanager.keyvault.models.Sku;
import com.azure.resourcemanager.keyvault.models.SkuFamily;
Expand Down Expand Up @@ -173,6 +174,13 @@ public boolean roleBasedAccessControlEnabled() {
return ResourceManagerUtils.toPrimitiveBoolean(innerModel().properties().enableRbacAuthorization());
}

@Override
public PublicNetworkAccess publicNetworkAccess() {
return (innerModel().properties() == null || innerModel().properties().publicNetworkAccess() == null)
? null
: PublicNetworkAccess.fromString(innerModel().properties().publicNetworkAccess());
}

@Override
public boolean enabledForDeployment() {
if (innerModel().properties() == null) {
Expand Down Expand Up @@ -415,6 +423,24 @@ public NetworkRuleSet networkRuleSet() {
return innerModel().properties().networkAcls();
}

@Override
public VaultImpl enablePublicNetworkAccess() {
if (innerModel().properties() == null) {
innerModel().withProperties(new VaultProperties());
}
this.innerModel().properties().withPublicNetworkAccess(PublicNetworkAccess.ENABLED.toString());
return this;
}

@Override
public VaultImpl disablePublicNetworkAccess() {
if (innerModel().properties() == null) {
innerModel().withProperties(new VaultProperties());
}
this.innerModel().properties().withPublicNetworkAccess(PublicNetworkAccess.DISABLED.toString());
return this;
}

@Override
public VaultImpl withAccessFromAllNetworks() {
if (innerModel().properties().networkAcls() == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ public interface Vault
*/
boolean roleBasedAccessControlEnabled();

/**
* Whether the vault can be accessed from public network.
*
* @return whether the vault can be accessed from public network.
*/
PublicNetworkAccess publicNetworkAccess();
Copy link
Member Author

@weidongxu-microsoft weidongxu-microsoft Mar 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about using boolean publicNetworkAccessEnabled() (as 1. it is two-value; 2. other service may not have the enum), but use this to be consistent with Registry and ManagedHsm.


/**
* @return whether Azure Virtual Machines are permitted to retrieve certificates stored as secrets from the key
* vault.
Expand Down Expand Up @@ -166,6 +173,12 @@ interface WithAccessPolicy {

/** A key vault definition allowing the networkAcl to be set. */
interface WithNetworkRuleSet {
/**
* Disables public network access for the vault, for private link feature.
*
* @return the next stage of the definition
*/
WithCreate disablePublicNetworkAccess();

/**
* Specifies that by default access to key vault should be allowed from all networks.
Expand Down Expand Up @@ -362,6 +375,19 @@ interface WithAccessPolicy {

/** A key vault update allowing the NetworkRuleSet to be set. */
interface WithNetworkRuleSet {
/**
* Enables public network access for the vault.
*
* @return the next stage of the update
*/
Update enablePublicNetworkAccess();

/**
* Disables public network access for the vault, for private link feature.
*
* @return the next stage of the update
*/
Update disablePublicNetworkAccess();

/**
* Specifies that by default access to key vault should be allowed from all networks.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.azure.resourcemanager.keyvault.models.CertificatePermissions;
import com.azure.resourcemanager.keyvault.models.KeyPermissions;
import com.azure.resourcemanager.keyvault.models.NetworkRuleBypassOptions;
import com.azure.resourcemanager.keyvault.models.PublicNetworkAccess;
import com.azure.resourcemanager.keyvault.models.SecretPermissions;
import com.azure.resourcemanager.keyvault.models.Vault;
import com.azure.core.management.Region;
Expand Down Expand Up @@ -282,6 +283,26 @@ public void canEnableSoftDeleteAndPurge() throws InterruptedException {
}
}

@Test
public void canDisablePublicNetworkAccess() {
Vault vault = keyVaultManager.vaults().define(vaultName)
.withRegion(Region.US_WEST)
.withNewResourceGroup(rgName)
.withEmptyAccessPolicy()
.disablePublicNetworkAccess()
.create();

Assertions.assertEquals(PublicNetworkAccess.DISABLED, vault.publicNetworkAccess());
Assertions.assertEquals(PublicNetworkAccess.DISABLED, keyVaultManager.vaults().getById(vault.id()).publicNetworkAccess());

vault.update()
.enablePublicNetworkAccess()
.apply();

Assertions.assertEquals(PublicNetworkAccess.ENABLED, vault.publicNetworkAccess());
Assertions.assertEquals(PublicNetworkAccess.ENABLED, keyVaultManager.vaults().getById(vault.id()).publicNetworkAccess());
}

private void assertVaultDeleted(String name, String location) {
boolean deleted = false;
try {
Expand Down
2 changes: 1 addition & 1 deletion sdk/resourcemanager/azure-resourcemanager/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "java",
"TagPrefix": "java/resourcemanager/azure-resourcemanager",
"Tag": "java/resourcemanager/azure-resourcemanager_e04fb35c26"
"Tag": "java/resourcemanager/azure-resourcemanager_b75c83930c"
}
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ public void testPrivateEndpointVault() {
.withRegion(region)
.withNewResourceGroup(rgName)
.withEmptyAccessPolicy()
.disablePublicNetworkAccess()
.create();

validatePrivateLinkResource(vault, subResourceName.toString());
Expand Down
Loading