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

Board Review: Add SharedKey/SAS Credential types to Azure.Core (all languages) #1954

Closed
tg-msft opened this issue Oct 20, 2020 · 9 comments
Closed
Assignees
Labels
architecture board-review Request for an Architectural Board Review

Comments

@tg-msft
Copy link
Member

tg-msft commented Oct 20, 2020

We have several services that support Shared Key and SAS credentials with the same API shape and usage:

Service Shared Key Shared Access Signature
Storage x x
Event Grid x
Event Hubs x x
Service Bus x x

I'd like to discuss adding AzureSharedKeyCredential and AzureSharedAccessSignatureCredential in Azure.Core so we don't have multiple copies of each.

(I'll edit in API specifics, a possible plan for refreshing SAS tokens automatically, and a plan for integration with the existing StorageSharedKeyCredential)

@tg-msft tg-msft added architecture board-review Request for an Architectural Board Review labels Oct 20, 2020
@tg-msft
Copy link
Member Author

tg-msft commented Oct 20, 2020

We should discuss together with #1942

@lilyjma
Copy link
Contributor

lilyjma commented Oct 27, 2020

scheduled for 10/28

@avg-msft
Copy link

@lilyjma Can we get a timeline on this, please? We have an SDK upgrade feature that is blocked on this.

@tg-msft
Copy link
Member Author

tg-msft commented Oct 28, 2020

Shared Key

After discussion, rather than add a specific AzureNamedKeyCredential we think it would make sense to augment AzureKeyCredential to allow an optional name:

 namespace Azure
 {
      public class AzureKeyCredential  {
         public AzureKeyCredential(string key);
+        public AzureKeyCredential(string name, string key);
+        public string Name { get; }
         [EditorBrowsable(EditorBrowsableState.Never)]
         public string Key { get; }
         public void Update(string key);
+        public void Update(string name, string key);
     }
 }

Additional topics to discuss:

  1. I think of signing with a shared key as slightly safer than passing an API key which is why I wanted separate types, but I agree that since it's a huge anti-pattern to use HTTP it won't matter to customers.
  2. Both values needs to update atomically. Could consider using a Tuple<string, string> for a single replacement instead of any synchronization.
  3. Storage will not update to derive StorageSharedKeyCredential : AzureKeyCredential because the property names don't align and there's no meaningful benefit of forcing it.
  4. EventHubs and ServiceBus should use this credential.
  5. Tables should replace its current SharedKey credential with this one.

@tg-msft
Copy link
Member Author

tg-msft commented Oct 28, 2020

SAS

While Storage currently takes SAS tokens as part of the URI and doesn't distinguish between anonymous auth and using SAS for auth, customers have found the inability to roll SAS tokens to be a pain point. See #1942 for more discussion about scenarios. We're proposing an API that looks like:

namespace Azure
{
    public class AzureSharedAccessSignatureCredential {
        public AzureSharedAccessSignatureCredential(string signature);
        [EditorBrowsable(EditorBrowsableState.Never)]
        public string Signature { get; }
        public void Update(string signature);
    }
}

Additional topics to discuss:

  1. Should we call it AzureSasCredential instead? Storage uses Sas for everything today.
  2. Clients libraries should throw if someone attempts to pass a SAS URI and a SAS credential. It's impossible to get this right in a perfectly forward compatible way, but we'll get a pretty clear auth error in the cases it's wrong.
  3. The exception message should point customers to things like BlobUriBuilder which makes it easy to remove a SAS token in code. Similar caveats about forward compat apply.
  4. We'd create a "shared source" pipeline policy that tacked on a SAS token to the URI per call. Today I think it would work across implementations.
  5. While there's not a scenario that requires it today, we can think about supporting automatic refresh in a future release. The pipeline policy would listen for 403s on the way back, check if the SAS token expired, raise an event (probably sync or async depending on the path), allow the event to compute/fetch a new SAS token, and mark the message as retriable so customers never notice the expiration. This could be added without breaking.
  6. Storage, EventHubs, and ServiceBus should use this credential.
  7. EventGrid should replace its current credential with this one.

@tg-msft
Copy link
Member Author

tg-msft commented Oct 28, 2020

Base Type

For anyone dealing with multiple types of credentials today, it's annoying that there's no base type. We're on the fence about creating something like:

namespace Azure.Core
{
    public abstract class AzureCredential { }
    public abstract class TokenCredential : AzureCredential { /* ... */ }
}

namespace Azure
{
    public class AzureKeyCredential : AzureCredential { /* ... */ }
    public class AzureSharedAccessSignatureCredential : AzureCredential { /* ... */ }
}

Additional topics to discuss:

  1. There will be no members. It's basically only for tagging.
  2. Do we want a less discoverable way of creating a client using the base AzureCredential for customers who are only holding one of these?

@tg-msft
Copy link
Member Author

tg-msft commented Oct 28, 2020

Recording (MS internal): https://msit.microsoftstream.com/video/0a25a1ff-0400-9fb2-9f3b-f1eb196ee5ee

Highlights:

  • AzureSasCredential makes sense to implement immediately
  • We'll see if there's time for a quick UX study around the proposed changes to AzureKeyCredential looking at
    • adding Name to AzureKeyCredential,
    • splitting into a separate AzureSharedKeyCredential,
    • or always using dedicated (Client)SharedKeyCredential types
  • We'll hold off on a base AzureCredential type for now and library authors can use object internally. We'll revisit when there's a customer scenario.

@lilyjma
Copy link
Contributor

lilyjma commented Oct 30, 2020

@avg-msft : Please take a look at Ted's last comment on the priorities we have now.

ghost pushed a commit to Azure/azure-sdk-for-python that referenced this issue Jan 6, 2021
**In this PR:**
- Add `AzureSasCredential` per Azure/azure-sdk#1954
- `AzureSasCredential` is the name that has been settled on the end of discussion.
- Add `AzureSasCredentialPolicy` that appends SAS to query

**Remarks:**
- Some service (like storage in the Portal) present SAS with leading "?". This has to be stripped before appending
- The validation if serviceUri already contain sas (mentioned [here](Azure/azure-sdk#1954 (comment))) will be responsibility of service clients:
    - the format varies between services (i.e. Event Grid SAS and Storage SAS are vastly different)
    - it would be good to fail fast (at client creation) rather than late (at request send).

**References**
- [.NET PR](Azure/azure-sdk-for-net#17636)
rakshith91 pushed a commit to rakshith91/azure-sdk-for-python that referenced this issue Jan 8, 2021
**In this PR:**
- Add `AzureSasCredential` per Azure/azure-sdk#1954
- `AzureSasCredential` is the name that has been settled on the end of discussion.
- Add `AzureSasCredentialPolicy` that appends SAS to query

**Remarks:**
- Some service (like storage in the Portal) present SAS with leading "?". This has to be stripped before appending
- The validation if serviceUri already contain sas (mentioned [here](Azure/azure-sdk#1954 (comment))) will be responsibility of service clients:
    - the format varies between services (i.e. Event Grid SAS and Storage SAS are vastly different)
    - it would be good to fail fast (at client creation) rather than late (at request send).

**References**
- [.NET PR](Azure/azure-sdk-for-net#17636)
@ramya-rao-a
Copy link
Contributor

I see the PRs in the .Net, Java and Python repo adding both AzureSasCredential and AzureSasCredentialPolicy. While I see the discussion and conclusion for the former in this issue, I don't see any for the latter. Can anyone shed some light on this?

Also, what is the update on AzureSharedKeyCredential?

nffdiogosilva pushed a commit to nffdiogosilva/azure-core that referenced this issue Oct 17, 2022
**In this PR:**
- Add `AzureSasCredential` per Azure/azure-sdk#1954
- `AzureSasCredential` is the name that has been settled on the end of discussion.
- Add `AzureSasCredentialPolicy` that appends SAS to query

**Remarks:**
- Some service (like storage in the Portal) present SAS with leading "?". This has to be stripped before appending
- The validation if serviceUri already contain sas (mentioned [here](Azure/azure-sdk#1954 (comment))) will be responsibility of service clients:
    - the format varies between services (i.e. Event Grid SAS and Storage SAS are vastly different)
    - it would be good to fail fast (at client creation) rather than late (at request send).

**References**
- [.NET PR](Azure/azure-sdk-for-net#17636)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
architecture board-review Request for an Architectural Board Review
Projects
None yet
Development

No branches or pull requests

6 participants