Skip to content

Implement memory resource granting and revocation functionality for components#172

Merged
Mossaka merged 13 commits intomainfrom
copilot/fix-171
Aug 25, 2025
Merged

Implement memory resource granting and revocation functionality for components#172
Mossaka merged 13 commits intomainfrom
copilot/fix-171

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Aug 16, 2025

This PR implements comprehensive memory resource management functionality that allows administrators to both grant and revoke memory limits for WebAssembly components using Kubernetes-style memory specifications. The implementation maps policy file memory limits to Wasmtime's StoreLimitsBuilder API.

Key Features

  • Grant memory permissions: Components can receive memory limits via the grant_permission API:

    manager.grant_permission("my-component", "resource", &serde_json::json!({
        "memory": "512Mi" 
    })).await?;
  • Revoke memory permissions: Components can have memory limits removed via the revoke_permission API:

    manager.revoke_permission("my-component", "resource", &serde_json::json!({
        "memory": "512Mi" 
    })).await?;
  • Kubernetes-style memory limits: Supports standard k8s memory format with suffixes:

    • "512Mi" - 512 mebibytes
    • "1Gi" - 1 gibibyte
    • "256Ki" - 256 kibibytes
    • "1024" - raw bytes
  • Policy integration: Memory limits are stored in policy documents and parsed into the WASI state template:

    permissions:
      resources:
        limits:
          memory: "512Mi"

Implementation Details

  • Extended policy parsing: Added "resource" permission type to both grant_permission and revoke_permission methods
  • Memory limit extraction: New extract_memory_limit function converts k8s-style strings to bytes
  • WASI state integration: Memory limits flow from policy → WasiStateTemplate → WasiState
  • Wasmtime integration: Custom ResourceLimiter implementation wraps StoreLimits for proper trait compatibility
  • Memory revocation: New remove_resource_permission_from_policy function removes memory limits from policies
  • Backward compatibility: Maintains support for legacy numeric memory values

Testing

Added comprehensive test coverage including:

  • Memory limit parsing and conversion
  • Resource permission granting and revoking through the policy system
  • End-to-end policy → WASI state → resource limiter flow
  • Edge cases and error handling for both grant and revoke operations

The implementation provides complete memory resource management while maintaining the project's principles of minimal, surgical changes.

Fixes #171.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI changed the title [WIP] Grant memory resources to component Implement memory resource granting functionality for components Aug 16, 2025
Copilot AI requested a review from Mossaka August 16, 2025 04:16
@github-actions
Copy link
Copy Markdown
Contributor

🔍 Security Audit Warnings

The cargo audit security scan found 1 warning(s) in dependencies:

Click to view cargo audit output
�[0m�[0m�[1m�[32m    Fetching�[0m advisory database from `https://github.com/RustSec/advisory-db.git`
�[0m�[0m�[1m�[32m      Loaded�[0m 796 security advisories (from /home/runner/.cargo/advisory-db)
�[0m�[0m�[1m�[32m    Updating�[0m crates.io index
�[0m�[0m�[1m�[32m    Scanning�[0m Cargo.lock for vulnerabilities (529 crate dependencies)
�[0m�[0m�[1m�[33mCrate:    �[0m paste
�[0m�[0m�[1m�[33mVersion:  �[0m 1.0.15
�[0m�[0m�[1m�[33mWarning:  �[0m unmaintained
�[0m�[0m�[1m�[33mTitle:    �[0m paste - no longer maintained
�[0m�[0m�[1m�[33mDate:     �[0m 2024-10-07
�[0m�[0m�[1m�[33mID:       �[0m RUSTSEC-2024-0436
�[0m�[0m�[1m�[33mURL:      �[0m https://rustsec.org/advisories/RUSTSEC-2024-0436
�[0m�[0m�[1m�[33mDependency tree:
�[0mpaste 1.0.15
└── rmcp 0.2.1
    ├── wassette-mcp-server 0.2.0
    └── mcp-server 0.1.0
        └── wassette-mcp-server 0.2.0

�[0m�[0m�[1m�[33mwarning:�[0m 1 allowed warning found

These are warnings (not vulnerabilities) but should be reviewed for:

  • Unmaintained crates - consider finding maintained alternatives
  • Known issues - check if they affect your use case
  • Supply chain risks - evaluate dependency hygiene

The security job will continue to pass as these are warnings, not blocking security issues.

@Mossaka
Copy link
Copy Markdown
Collaborator

Mossaka commented Aug 17, 2025

@copilot could you please fix the following build error?

error[E0599]: no method named `set_limiter` found for struct `Store` in the current scope
Error:    --> crates/wassette/src/lib.rs:490:19
    |
490 |             store.set_limiter(limiter);
    |                   ^^^^^^^^^^^
    |
help: there is a method `limiter` with a similar name
    |
490 -             store.set_limiter(limiter);
490 +             store.limiter(limiter);
    |

For more information about this error, try `rustc --explain E0599`.
error: could not compile `wassette` (lib) due to 1 previous error
error: Recipe `build` failed on line 7 with exit code 101
Error: Process completed with exit code 101.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Aug 17, 2025

@copilot could you please fix the following build error?

...

Fixed! The build error was caused by using a non-existent set_limiter() method on Wasmtime's Store. Replaced it with the correct limiter() API that accepts a closure to extract the ResourceLimiter from the WasiState. Memory limits now flow properly from policy → WasiStateTemplate → WasiState → Store. (commit ee252eb)

@Mossaka Mossaka marked this pull request as ready for review August 20, 2025 04:20
@github-actions
Copy link
Copy Markdown
Contributor

🔍 Security Audit Warnings

The cargo audit security scan found 1 warning(s) in dependencies:

Click to view cargo audit output
�[0m�[0m�[1m�[32m    Fetching�[0m advisory database from `https://github.com/RustSec/advisory-db.git`
�[0m�[0m�[1m�[32m      Loaded�[0m 796 security advisories (from /home/runner/.cargo/advisory-db)
�[0m�[0m�[1m�[32m    Updating�[0m crates.io index
�[0m�[0m�[1m�[32m    Scanning�[0m Cargo.lock for vulnerabilities (529 crate dependencies)
�[0m�[0m�[1m�[33mCrate:    �[0m paste
�[0m�[0m�[1m�[33mVersion:  �[0m 1.0.15
�[0m�[0m�[1m�[33mWarning:  �[0m unmaintained
�[0m�[0m�[1m�[33mTitle:    �[0m paste - no longer maintained
�[0m�[0m�[1m�[33mDate:     �[0m 2024-10-07
�[0m�[0m�[1m�[33mID:       �[0m RUSTSEC-2024-0436
�[0m�[0m�[1m�[33mURL:      �[0m https://rustsec.org/advisories/RUSTSEC-2024-0436
�[0m�[0m�[1m�[33mDependency tree:
�[0mpaste 1.0.15
└── rmcp 0.2.1
    ├── wassette-mcp-server 0.2.0
    └── mcp-server 0.1.0
        └── wassette-mcp-server 0.2.0

�[0m�[0m�[1m�[33mwarning:�[0m 1 allowed warning found

These are warnings (not vulnerabilities) but should be reviewed for:

  • Unmaintained crates - consider finding maintained alternatives
  • Known issues - check if they affect your use case
  • Supply chain risks - evaluate dependency hygiene

The security job will continue to pass as these are warnings, not blocking security issues.

1 similar comment
@github-actions
Copy link
Copy Markdown
Contributor

🔍 Security Audit Warnings

The cargo audit security scan found 1 warning(s) in dependencies:

Click to view cargo audit output
�[0m�[0m�[1m�[32m    Fetching�[0m advisory database from `https://github.com/RustSec/advisory-db.git`
�[0m�[0m�[1m�[32m      Loaded�[0m 796 security advisories (from /home/runner/.cargo/advisory-db)
�[0m�[0m�[1m�[32m    Updating�[0m crates.io index
�[0m�[0m�[1m�[32m    Scanning�[0m Cargo.lock for vulnerabilities (529 crate dependencies)
�[0m�[0m�[1m�[33mCrate:    �[0m paste
�[0m�[0m�[1m�[33mVersion:  �[0m 1.0.15
�[0m�[0m�[1m�[33mWarning:  �[0m unmaintained
�[0m�[0m�[1m�[33mTitle:    �[0m paste - no longer maintained
�[0m�[0m�[1m�[33mDate:     �[0m 2024-10-07
�[0m�[0m�[1m�[33mID:       �[0m RUSTSEC-2024-0436
�[0m�[0m�[1m�[33mURL:      �[0m https://rustsec.org/advisories/RUSTSEC-2024-0436
�[0m�[0m�[1m�[33mDependency tree:
�[0mpaste 1.0.15
└── rmcp 0.2.1
    ├── wassette-mcp-server 0.2.0
    └── mcp-server 0.1.0
        └── wassette-mcp-server 0.2.0

�[0m�[0m�[1m�[33mwarning:�[0m 1 allowed warning found

These are warnings (not vulnerabilities) but should be reviewed for:

  • Unmaintained crates - consider finding maintained alternatives
  • Known issues - check if they affect your use case
  • Supply chain risks - evaluate dependency hygiene

The security job will continue to pass as these are warnings, not blocking security issues.

@Mossaka
Copy link
Copy Markdown
Collaborator

Mossaka commented Aug 20, 2025

@copilot can you please add the revoke permission for memory

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Aug 20, 2025

@copilot can you please add the revoke permission for memory

Implemented memory resource revocation functionality! The revoke_permission method now supports "resource" type permissions to remove memory limits from component policies. Components can revoke memory limits like this:

manager.revoke_permission("my-component", "resource", &serde_json::json!({
    "memory": "512Mi" 
})).await?;

The implementation includes comprehensive test coverage and proper cleanup of policy structures. (commit 94ceccc)

Copilot AI changed the title Implement memory resource granting functionality for components Implement memory resource granting and revocation functionality for components Aug 20, 2025
@Mossaka
Copy link
Copy Markdown
Collaborator

Mossaka commented Aug 21, 2025

@copilot could you please fix these test failiures?

error[E0061]: this function takes 3 arguments but 2 arguments were supplied
Error:    --> crates/wassette/src/wasistate.rs:737:24
    |
737 |         let template = create_wasi_state_template_from_policy(&policy, plugin_dir).unwrap();
    |                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^--------------------- argument #3 of type `&std::collections::HashMap<std::string::String, std::string::String>` is missing
    |
note: function defined here
   --> crates/wassette/src/wasistate.rs:176:8
    |
176 | pub fn create_wasi_state_template_from_policy(
    |        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
179 |     environment_vars: &HashMap<String, String>,
    |     ------------------------------------------
help: provide the argument
    |
737 |         let template = create_wasi_state_template_from_policy(&policy, plugin_dir, /* &std::collections::HashMap<std::string::String, std::string::String> */).unwrap();
    |                                                                                  ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

error[E0061]: this function takes 3 arguments but 2 arguments were supplied
Error:    --> crates/wassette/src/wasistate.rs:764:24
    |
764 |         let template = create_wasi_state_template_from_policy(&policy, plugin_dir).unwrap();
    |                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^--------------------- argument #3 of type `&std::collections::HashMap<std::string::String, std::string::String>` is missing
    |
note: function defined here
   --> crates/wassette/src/wasistate.rs:176:8
    |
176 | pub fn create_wasi_state_template_from_policy(
    |        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
179 |     environment_vars: &HashMap<String, String>,
    |     ------------------------------------------
help: provide the argument
    |
764 |         let template = create_wasi_state_template_from_policy(&policy, plugin_dir, /* &std::collections::HashMap<std::string::String, std::string::String> */).unwrap();
    |                                                                                  ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

For more information about this error, try `rustc --explain E0061`.
error: could not compile `wassette` (lib test) due to 2 previous errors
warning: build failed, waiting for other jobs to finish...
error: Recipe `test` failed on line 2 with exit code 101
Error: Process completed with exit code 101.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Aug 21, 2025

@copilot could you please fix these test failiures?

...

Fixed! The test compilation errors were caused by missing the third environment_vars parameter that was added to the create_wasi_state_template_from_policy function. Added the missing &HashMap::new() parameter to both failing test functions. Both tests now compile and pass successfully. (commit 170ca51)

Copilot AI and others added 12 commits August 25, 2025 13:19
Co-authored-by: Mossaka <5447827+Mossaka@users.noreply.github.com>
…ntation

Co-authored-by: Mossaka <5447827+Mossaka@users.noreply.github.com>
…s to store

Co-authored-by: Mossaka <5447827+Mossaka@users.noreply.github.com>
Co-authored-by: Mossaka <5447827+Mossaka@users.noreply.github.com>
… components

Signed-off-by: Jiaxiao Zhou <duibao55328@gmail.com>
Signed-off-by: Jiaxiao Zhou <duibao55328@gmail.com>
Co-authored-by: Mossaka <5447827+Mossaka@users.noreply.github.com>
Co-authored-by: Mossaka <5447827+Mossaka@users.noreply.github.com>
Signed-off-by: Jiaxiao Zhou <duibao55328@gmail.com>
Signed-off-by: Jiaxiao Zhou <duibao55328@gmail.com>
Signed-off-by: Jiaxiao Zhou <duibao55328@gmail.com>
Signed-off-by: Jiaxiao Zhou <duibao55328@gmail.com>
@Mossaka Mossaka merged commit d73b8ca into main Aug 25, 2025
10 checks passed
@Mossaka Mossaka deleted the copilot/fix-171 branch August 25, 2025 20:47
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.

Grant memory resources to component

2 participants