Implement access control on Spring Cloud applications by using service authentication

更新时间:
复制 MD 格式

When multiple microservices share a namespace, any consumer can call any provider path by default. Service authentication restricts this access by letting you define whitelist and blacklist rules that control which consumer applications can reach specific provider paths. This protects sensitive endpoints -- such as those that handle core business logic or core data -- from unauthorized internal calls.

How it works

Service authentication evaluates incoming calls against two types of rules: global rules and path-specific rules.

Without service authentication, all consumers in a namespace can call all paths of a provider:

Do not configure service authentication

With service authentication, you control access at two levels:

Rule typeScopeLimit
Global ruleAll paths of a providerOne per provider
Path-specific ruleA single path of a providerMultiple allowed

For example, you can:

  • Create a global rule that blacklists Consumer 1 (blocked from all paths) and whitelists Consumers 2 and 3 (allowed to call all paths).

  • Create a path-specific rule that blacklists Consumer 2 from Path 2 (which involves core business or core data), so Consumer 2 can only call Paths 1 and 3.

Service authentication configured

Rule override behavior

A path-specific rule fully replaces the global rule for that path -- it does not append to it.

ScenarioGlobal rulePath-specific rule (Path 2)Result for Path 2
Path-specific narrows accessWhitelist: Consumers 2, 3Whitelist: Consumer 3 onlyConsumer 2 loses access to Path 2; Consumer 3 retains access
Path-specific blocks one consumerWhitelist: Consumers 2, 3Blacklist: Consumer 2Consumer 2 is blocked from Path 2; Consumer 3 follows global rule
No path-specific ruleWhitelist: Consumers 2, 3(none)Consumers 2 and 3 can call Path 2 per the global rule
Important

When you create a path-specific rule, carefully re-specify all consumers that should have access to that path. The global rule no longer applies to the path.

Create a service authentication rule

Prerequisites

Before you begin, make sure that you have:

  • An EDAS account with access to the EDAS console

  • At least one Spring Cloud provider application deployed in a microservice namespace

  • At least one consumer application deployed in the same namespace

Procedure

  1. Log on to the EDAS console.

  2. In the left-side navigation pane, choose Traffic Management > Microservices Governance > Spring Cloud.

  3. In the left-side navigation tree of Spring Cloud, click Service Authentication.

  4. On the Service Authentication page, click Create rules.

  5. On the Create rules page, configure the parameters described in the following sections, and then click OK.

    Service Authentication  / /> Create rules

Basic parameters

ParameterDescription
Microservice NamespacesThe region and microservice namespace where the provider is deployed.
Rule nameA name for the rule. Maximum 64 characters. Supports letters, digits, underscores (_), and hyphens (-).
The calleeThe provider application to protect.
Callee frameworkThe framework of the provider. Select Spring Cloud.
Default StateOn (default): The rule takes effect immediately after creation. Off: The rule is saved but not enforced. To enable it later, click Open in the Operation column on the Service Authentication page.

Global rule parameters (Add all interface rules)

Click Add all interface rules to define a rule that applies to all paths of the provider. Only one global rule is allowed per provider.

ParameterDescription
Callee interfaceFixed to All Path.
Authentication methodWhitelist (allow calls): Only listed consumers can call the provider. Blacklist (call denied): Listed consumers are blocked from calling the provider.
CallerThe consumer applications to authenticate. Click Add caller to select multiple applications.

Path-specific rule parameters (Add specified interface rule)

Click Add specified interface rule to define a rule that targets a single path. This rule overrides the global rule for that path.

ParameterDescription
Callee PathThe specific path to protect.
Authentication methodWhitelist (allow calls) or Blacklist (call denied).
CallerThe consumer applications to authenticate. Click Add caller to select multiple applications.

Verify the result

After the rule is created and enabled, confirm that it works as expected:

  1. Send a request from a blocked consumer to the provider. The request should fail with an authentication error.

  2. Send a request from an allowed consumer to the same provider path. The request should return a successful response.

  3. If you configured a path-specific rule, verify that the blocked consumer can still access other paths not covered by that rule.

Manage existing rules

On the Service Authentication page, use the Operation column to manage rules:

ActionDescription
EditModify the rule configuration.
CloseDisable an active rule. The rule is preserved but no longer enforced.
OpenRe-enable a disabled rule.
DeletePermanently remove the rule.