Yoshua Wuyts
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # dacquiri notes (dan, d0nut, yosh) github: https://github.com/resyncgg/dacquiri - let the compiler inform what needs to be done instead of talking to people - this requires inverting the model from top-to-bottom - make the compiler enforce that the access-control has occurred for every code path - this lowers the boundary to author secure software - annotate the low level methods to do this ## Terminology - **attributes**: the conditions that you'd typically write if-statements for - **policies**: the thing we annotate methods with. They're collections of attributes. They need to be enforced ahead of time - **entities**: the things that can have attributes on them. - **entity store**: holds onto entities so we can use them later ## Dacquiri example - say we want to enforce two properties on a function - user is enabled - user is owner of document - we write a function assuming access is already validated - policy enforces that the properties are checked - this enforces ```rust #[get("/documents/{doc_id}")] async fn access_document(req: HttpRequest, session: Session, doc_id: Path<String>) -> impl Responder { let document_service = req.get_document_service(); let doc_id = doc_id.into_inner(); let document_meta = document_service.fetch_doc_metadata(doc_id).await?; // coalesce our entities let entities = session .into_entity::<"user">() .add_entity::<_, "document_metadata">(document_meta)?; // prove our properties let proof = entities.check_caller_owns_document::<"user", "document_metadata">()?; // call the protected function! proof.fetch_document_contents(&document_service).await } ``` We want this trait implemented: ```rust HasEntity<User, "user"> ``` ```rust ConstraintChain<..., ..., ConstraintChain<..., .., <etc>>> ``` ### How dynamic is this system? - user is enabled - can the user be disabled dynamically? - answer: once you've checked, it's assumed that a property will hold - particularly optimized for things like short-lived HTTP requests - You can work around this tho! - You could have things where you re-check things by revoking permissions. - May introduce a "live check" attribute Can we be specific on how this differs from with clauses - `with`-clauses require you to defer the type ahead of time. Here the attributes are stringly typed. ## with clauses blog post: https://tmandry.gitlab.io/blog/posts/2021-12-21-context-capabilities/ ```rust capability arena: Arena; trait Arena {..}; struct BasicArena {..} ``` ```rust use arena::{basic_arena, BasicArena}; struct Bar<'a> { version: i32, foo: &'a Foo, } // Here the `with` clause is used only for invoking the `Deserialize` // impl for Foo; we never use `basic_arena` directly. impl<'a> Deserialize for Bar<'a> with basic_arena: &'a BasicArena, { fn deserialize( deserializer: &mut Deserializer ) -> Result<Self, Error> { let version = deserializer.get_key("version")?; let foo = deserializer.get_key("foo")?; Ok(Bar { version, foo }) } } ``` ```rust= fn access_document() with user: User { ... } ``` ```rust= fn access_document() with user: User, { ... } ``` ```rust= fn access_domain() with user: User, document: Document, UserOwnsDocument (with user + document), { // stuff } ``` ```rust= fn toplevel() { } fn access_document(doc: AccessibleDocument) { log(doc.user()); } ``` an admin may want to transfer data from one team to another - uniqueness of type - we don't just want to show we can transfer from a team to another team - we want to be able to talk about _specific instances of types_ Yosh wonders whether we're missing a core type system thing: ```rust fn square<T: Mult>(n1: T, n2: T) {..} // no guarantee n1 and n2 are _identical_ values, only identical types ``` https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=8933aa6fe11679734c8ff5aa7550f778 ```rust #![feature(generic_const_exprs)] fn main() { println!("{}", multi::<10, 10>()); //println!("{}", multi::<10, 12>()); } fn multi<const N: u32, const M: u32>() -> u32 where If<{N == M}>: True { N * M } struct If<const Cond: bool> {} trait True {} impl True for If<true> {} ``` All of dacquiri is designing around a way to narrow types. In typescript you can have a type which says: "this is an A or a B". ## Alternate - Instead guaranteeing uniqueness of instance, factor out the authentication and make that return a new type to guarantee the validation. ```rust= fn square(args: SquareArgs) -> i32 { args.x() * args.y() } fn make_args(x: i32, y: i32) -> SquareArgs { assert!(x == y); SquareArgs::new(x, y) } ``` "from this point onward, guarantee that thing is validated" ```rust let validated_user = validate_user(&user)?; some_doc.change_author(validated_user, new_author); // with with-clauses with validate_user(&user)? { some_doc.change_author(new_author); } ``` - Rather than validating the user and returning a validated user, instead validate the document with the user and return a new type of document. - From a capability perspective user's are overly coarse-grained - You want to get rid of the user as soon as you can. - Instead you want to pass the document around which is a type with the permissions baked in. ```rust let open_doc: OpenDoc = carefully_open_document(&user, doc_id)?; open_doc.change_author(new_author); ``` https://blog.yoshuawuyts.com/state-machines-2/ ```rust let open_doc: OpenDoc<DocPermission::Admin> = ...; let open_doc: Something<OpenDoc> = ...; ``` Thing we haven't covered with this: the intersection stuff (`OR` clauses). We should revisit this. Yosh suspects view types may help here: ```rust let open_doc: OpenDoc<Permissions { Read: true, Write: true }> = ...; ``` Ergomics rule: if you hit 2/3 states in an enum, methods which are only available on those 2 cases should always be available if you unambiguously know that that's available.

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully