8000 Add support for Immutable Storage on container by xperiandri · Pull Request #1144 · CompositionalIT/farmer · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add support for Immutable Storage on container #1144

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

Closed

Conversation

xperiandri
Copy link
Contributor
@xperiandri xperiandri commented Oct 24, 2024

Implemented:

  • ImmutableStorageWithVersioning
  • RequireInfrastructureEncryptionThis PR closes #

I have read the contributing guidelines and have completed the following:

  • Tested my code end-to-end against a live Azure subscription.
  • Updated the documentation in the docs folder for the affected changes.
  • Written unit tests against the modified code that I have made.
  • Updated the release notes with a new entry for this PR.
  • Checked the coding standards outlined in the contributions guide and ensured my code adheres to them.

If I haven't completed any of the tasks above, I include the reasons why here:
Which test would you recommend to modify or implement?

Below is a minimal example configuration that includes the new features, which can be used to deploy to Azure:

let storage = storageAccount {
    name "wormtest222"
    sku Farmer.Storage.Sku.Standard_GRS
    disable_blob_public_access
    add_private_container
        "container"
        (blobContainerImmutabilityPolicies {
            allow_protected_append_writes AllAppendAllowed
            immutability_period_since_creation (365<Days> * 5)
        })
}

@xperiandri xperiandri force-pushed the storage-2023-05-01 branch 3 times, most recently from de707a0 to 3c3a3d8 Compare October 25, 2024 12:51
@xperiandri
Copy link
Contributor Author

@ninjarobot do you have any remarks?

@isaacabraham
Copy link
Member

You want to write at least one test confirmation the JSON that is emitted in the generate ARM template is correct i.e. checking fields etc.

@isaacabraham
Copy link
Member

From an API design, what happens if you don't want to set any policies - do you need to provide a policy regardless (bear in mind computation expressions don't allow optional arguments AFAIK, and overloads must all have the same number of arguments)? I think perhaps creating a dedicated container { } CE which can have members on it including e.g.:

  • name
  • accessibility (public / private)
  • immutability_policy

would be a better way to go.

@isaacabraham
Copy link
Member

Also can you make an issue first which clearly outlines what this PR is designed to solve - normally we create issues, get them approved, and then create a PR to resolve them (in that order :-))

Copy link
Collaborator
@ninjarobot ninjarobot left a comment

Choose a reason for hiding this comment

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

Looks great, thanks for adding this support for newer storage account functionality. I made a few minor suggestions you can take or leave as applicable.

DefaultToOAuthAuthentication = this.DefaultToOAuthAuthentication
DnsZoneType = this.DnsZoneType
EnableHierarchicalNamespace = this.EnableDataLake
ImmutableStorageWithVersioning = None // TODO: Implement
Copy link
Collaborator

Choose a reason for hiding this comment

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

This looks implemented, so can remove the TODO, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ninjarobot I mean here that there is not such operation in the builder. That is what needs to be implemented

Copy link
Member

Choose a reason for hiding this comment

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

Let's use GitHub issues rather than TODO comments to track possible enhancements. Would you mind creating one @xperiandri?

@ninjarobot ninjarobot added this to the 1.9.3 milestone Oct 26, 2024
@isaacabraham isaacabraham self-requested a review October 27, 2024 14:54
Copy link
Member
@isaacabraham isaacabraham left a comment

Choose a reason for hiding this comment

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

Before merging, we need to modify the API - the use of a CE in this regard isn't going to work, from what I can see, from a usability perspective.

@xperiandri
Copy link
Contributor Author

From an API design, what happens if you don't want to set any policies - do you need to provide a policy regardless (bear in mind computation expressions don't allow optional arguments AFAIK, and overloads must all have the same number of arguments)?

@isaacabraham, actually it works fine as all the tests pass. I verified that it works both ways and allow that optional parameter to be specified and omitted

@isaacabraham
Copy link
Member

@isaacabraham, actually it works fine as all the tests pass. I verified that it works both ways and allow that optional parameter to be specified and omitted

That's good :-) Nonetheless, I think moving to a dedicated container { } CE at this stage makes more sense.

This PR still needs tests for the new code that's been created as well as the other points mentioned (including an issue / issues that reflect the actual changes that are being made here - it's not so much about upgrading the versions but about immutable blobs etc.).

Happy to talk through with you the API choices and anything else that's needed.

@xperiandri
Copy link
Contributor Author

I thought about that but considered immutable policy as not so big change to introduce container CE.
However further container customization support may need a CE

@xperiandri
Copy link
Contributor Author

I've implemented tests. Let me know if I miss something

@xperiandri
Copy link
Contributor Author

Before merging, we need to modify the API - the use of a CE in this regard isn't going to work, from what I can see, from a usability perspective.

@isaacabraham my idea was to add now and preserve in the future ability to specify immutability policy
And add blobContainer CE and operations to storageAccount CE accepting BlobContainerConfig along with supporting additional container settings.
I have no intent to add them right now as it widens the scope of this PR.
Do you think blobContainer should be coupled with these changes?

@isaacabraham
Copy link
Member

I think so, yes. If you look elsewhere in the Farmer API, you won't really much in the way of CEs being supplied as secondary arguments to a custom keyword, and I really would like to retain the pattern that we have.

You can repurpose the CE you've already built to actually be the container one - just add in the extra name parameter. You can then add that as an overload for the top-level CE add_private_container member.

What do you think?

Thanks for adding the tests.

@ninjarobot ninjarobot modified the milestones: 1.9.3, 1.9.4 Nov 3, 2024
@isaacabraham isaacabraham changed the title Updated Microsoft.Storage/storageAccounts to 2023-05-01 Add support for Immutable Storage on container Nov 5, 2024
@ninjarobot ninjarobot modified the milestones: 1.9.4, 1.9.5, 1.9.6 Nov 6, 2024
@xperiandri xperiandri force-pushed the storage-2023-05-01 branch 2 times, most recently from 6a01d5e to 21088d9 Compare November 15, 2024 14:52
@xperiandri
Copy link
Contributor Author

@isaacabraham I've implemented storageBlobContainer CE as you suggested.
Any other remarks?

@mattgallagher92
Copy link
Member

@xperiandri I've looked at the parts where you had TODOs in more depth based on ImmutableStorageWithVersioning. I see that there are two cases:

  • The immutableStorageWithVersioning field in the ARM template has a representation in the StorageAccount type that implements IArmResource, which affects the generated JSON. However there is no corresponding configuration available in the builder, and no test that the generated JSON is correct.
  • The extendedLocation and identity fields will always be se 62FB t to null in the generated JSON.

I have a few questions:

  • Why did you add them if they're not used? Are the fields required in the ARM template JSON?
  • If not, why not just leave them out of the Farmer codebase altogether?
  • Why have you made immutableStorageWithVersioning configurable via the F# type but not done the same for extendedLocation and identity?

@xperiandri
Copy link
Contributor Author

Why did you add them if they're not used? Are the fields required in the ARM template JSON?

Not required, just to mark they exist but not implemented

If not, why not just leave them out of the Farmer codebase altogether?

I can if you prefer

Why have you made immutableStorageWithVersioning configurable via the F# type but not done the same for extendedLocation and identity

I only implemented the piece I need and the scope defined by the PR name

@mattgallagher92
Copy link
Member

Why have you made immutableStorageWithVersioning configurable via the F# type but not done the same for extendedLocation and identity

I only implemented the piece I need and the scope defined by the PR name

So you're using it directly on the Farmer.Arm.Storage.StorageAccount type rather than via the computation expression?

A8CD
Comment on lines +964 to +1036
type BlobContainerImmutabilityPoliciesBuilder() =
member _.Yield _ =
BlobContainerImmutabilityPoliciesConfig.Empty

member _.Run state : BlobContainerImmutabilityPoliciesConfig = state

/// Sets the AllowProtectedAppendWrites property.
[<CustomOperation "allow_protected_append_writes">]
member _.AllowProtectedAppendWrites(state: BlobContainerImmutabilityPoliciesConfig, value) = {
state with
AllowProtectedAppendWrites = Some value
}

/// Sets the ImmutabilityPeriodSinceCreation property.
[<CustomOperation "immutability_period_since_creation">]
member _.ImmutabilityPeriodSinceCreation(state: BlobContainerImmutabilityPoliciesConfig, value) = {
state with
ImmutabilityPeriodSinceCreation = Some value
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

So you're using it directly on the Farmer.Arm.Storage.StorageAccount type rather than via the computation expression?

@mattgallagher92 no, here is the builder

Copy link
Member

Choose a reason for hiding this comment

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

That affects Farmer.Arm.Storage.BlobContainers.ImmutabilityPolicies. I'm referring to Farmer.Arm.Storage.StorageAccount.

ImmutableStorageWithVersioning:
{|
Enable: bool option
ImmutabilityPolicy:
{|
AllowProtectedAppendWrites: bool option
ImmutabilityPeriodSinceCreation: int<Days> option
State: ImmutabilityPolicyState option
|} option
|} option

Copy link
Contributor Author
@xperiandri xperiandri Mar 29, 2025

Choose a reason for hiding this comment

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

I still have not got what your question is about.
Isaac asked to create a container CE.
I need immutability policies, so I also created CE for them.
So now we have blob container and blob container immutability policies CEs, and corresponding properties for them within the StorageAccount record.

Could you describe again what inconsistency you have found?

Copy link
Member

Choose a reason for hiding this comment

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

Sure 🙂 Thanks for your patience and sorry that this is dragging on so long. I don't have a lot of time available to review this (and unfortunately I'm going to be unavailable over the next few weeks).

When I search for references to the ImmutableStorageWithVersioning property on Farmer.Arm.Storage.StorageAccount, I see that it's used in 4 places. 3 of those places set it to None, and the remaining place uses it via Option.map, which will therefore also always return None. As far as I can see, there doesn't seem to be any means of setting it to anything other than None via a builder, so it seems to be that the Option.map code is not being tested and is perhaps even redundant.

Given it doesn't seem to be possible to set it via builder, I wondered whether you were setting the field directly on the record somehow, or whether this is something that you don't need.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mattgallagher92 fixed, please review again

Copy link
Member

Choose a reason for hiding this comment

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

@xperiandri I see a commit labelled Implemented storage account level immutability policy setting and builder, but I don't actually see the implementation in the diff?

@ninjarobot ninjarobot modified the milestones: 1.9.13, 1.9.14, 1.9.15 May 12, 2025
@ninjarobot ninjarobot modified the milestones: 1.9.15, 1.9.16 May 27, 2025
@mattgallagher92
Copy link
Member

@xperiandri I've re-reviewed. The unresolved conversations are the things that have not been addressed.

Note for other maintainers: I'm leaving Compositional IT, so I'm not going to be able to re-review this. There are a few unresolved conversations, but I think that this is good enough to go in as it is. Hopefully Andrii can easily add the missing builder implementation that is mentioned in the latest commit message (e0e6cea), but not actually present in the diff. Once that's done, the other changes are minor ones that maintainers can make before merging.

If preferred for whatever reason, I think that it would be reasonable to merge the code as is and make the outstanding tweaks later - the code is good enough.

@FundOurselves FundOurselves closed this by deleting the head repository Jun 13, 2025
@xperiandri
Copy link
Contributor Author
xperiandri commented Jun 13, 2025

I thought I have finally implemented all the builders

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
0