Skip to content

add(ocm): shared OCM HTTP transport package - #5833

Merged
glpatcern merged 5 commits into
masterfrom
refactor-ocm-http-transport-config
Oct 1, 2026
Merged

glpatcern merged 5 commits into
masterfrom
refactor-ocm-http-transport-config

Conversation

@MahdiBaghbani

@MahdiBaghbani MahdiBaghbani commented Sep 21, 2026 •

Copy link
Copy Markdown
Member

This PR is part of the cs3org/OCM-STA#48

Summary

  • Add pkg/ocm/client, a shared OCM HTTP transport package with TransportConfig and trusted/public-only HTTP client constructors, centralizing transport and address-policy logic currently inlined in ocmd. Existing ocmd.OCMClient callers are unchanged; public-only clients still bypass environment proxies and use the guarded dialer.
  • Supersedes feat(ocm): Strengthen OCM client security #5389.

@MahdiBaghbani

MahdiBaghbani commented Sep 23, 2026 •

Copy link
Copy Markdown
Member Author

This pulls the OCM transport into one TransportConfig in pkg/ocm/client so the rest of the stack shares a single dial policy. Existing ocmd constructor signatures don't change.

flowchart TD
    CFG["TransportConfig"] --> T["trusted client"]
    CFG --> P["public-only client"]
    T --> TP["always ProxyFromEnvironment"]
    P --> G["Dialer.Control"]
    G --> Z{"zoned IPv6?"}
    Z -->|yes| R["reject"]
    Z -->|no| IP["isAllowedIP"]
    P --> PX{"UseEnvProxy"}
    PX -->|false, default| D["Proxy = nil"]
    PX -->|true| E["ProxyFromEnvironment"]
Loading

The zone check is the part you might ask about. netip.Prefix.Contains returns false for any zoned address, so something like 64:ff9b::a9fe:a9fe%0 used to slip past the NAT64 and denied-prefix checks.

I reject zones outright instead of stripping them, since a public-only client has no reason to honor a link-local zone.

The other thing is UseEnvProxy. It defaults to false. If you turn it on, Control checks the proxy hop and not the OCM target, so it's an operator opt-in and doesn't add a second guarded mode.

The proxy change is its own commit, so it can be reverted without touching the zone fix.

And the reason is that you might need to have all your OCM outbound routed through MITM, like I do when I'm in the Test Suite.

@MahdiBaghbani

MahdiBaghbani commented Sep 24, 2026 •

Copy link
Copy Markdown
Member Author

Hi Giuseppe, good question in Matrix. I went to check all the places and the distinction between trusted and untrusted.

A party counts as trusted once the operator has admitted it through the provider authorizer (mentix or the json file), and that's what IsProviderAllowed checks at /ocm/invite-accepted and /ocm/shares.

flowchart LR
    Auth["provider authorizer (mentix / json)"] --> Gate{"IsProviderAllowed"}
    Gate -->|admitted| GI["GetInfoByDomain"]
    GI --> T["NewTrustedHTTPClient"]
    Dir["WAYF configured directory URLs"] --> T
    T --> T1["invite manager: InviteAccepted"]
    T --> T2["share provider: NewShare"]
    Gate -->|unknown or caller-named host| P["NewPublicOnlyHTTPClient"]
    P --> P1["inbound /shares: sender IdP + WebDAV"]
    P --> P2["received-share storage: WebDAV"]
    P --> P3["open authorizer probe"]
    P --> P4["WAYF untrustedClient: /discover + listed servers"]
Loading

The trusted client keeps the env proxy and skips the dial guard, and it's used in exactly three places:

  1. WAYF dialing the directory URLs from config.
  2. The invite manager calling InviteAccepted.
  3. The share provider calling NewShare.

In the two gRPC cases the target comes from GetInfoByDomain, so it's the authorizer picking the host and not the caller.

Anywhere a caller gets to name the host, it goes through the public-only client.

One thing I want to be sure about:
those two gRPC call sites take the ProviderInfo they're handed and don't run IsProviderAllowed again before dialing.
Right now, that's safe because the HTTP handlers always resolve through GetInfoByDomain first, but the check lives upstream and not at the dial site. I can add a re-check there if you think it's worth it.

@MahdiBaghbani

MahdiBaghbani commented Sep 26, 2026 •

Copy link
Copy Markdown
Member Author

This adds an explicit private-network exception to the public-only client.

ParseFederationCIDRs turns a list of CIDR strings into an immutable FederationCIDRs, and TransportConfig.AllowedFederationCIDRs carries it into the dial guard.

The zero value allows nothing, so behavior doesn't change until a service sets it. The next PRs wire it up as allowed_federation_cidrs.

flowchart TD
    IN["CIDR strings from service config"] --> PF["ParseFederationCIDRs"]
    PF -->|"any invalid entry"| ERR["whole list rejected"]
    PF -->|"ok"| TC["TransportConfig.AllowedFederationCIDRs"]
    TC --> D["newPublicOnlyDialer, policy cloned"]
    D --> Z{"zoned IPv6?"}
    Z -->|"yes"| R["refuse"]
    Z -->|"no"| LB{"loopback and AllowLoopback?"}
    LB -->|"yes"| OK["dial"]
    LB -->|"no"| PUB{"public IP?"}
    PUB -->|"yes"| OK
    PUB -->|"no"| PR{"private and inside a listed CIDR?"}
    PR -->|"yes"| OK
    PR -->|"no"| R
Loading

The parser is strict on purpose. Each entry has to be a canonical prefix with host bits cleared and sit wholly inside 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 or fc00::/7, and one bad entry rejects the whole list.

So 127.0.0.0/8, fe80::/10 or 10.1.2.3/8 fail at startup instead of quietly widening the guard.

This is also the piece I need for the Test Suite. There the MITM sits on a private Docker network, and with UseEnvProxy on the guard sees the proxy hop, not the OCM target, so the proxy's range has to be listed. It doesn't make the proxy enforce target ranges though, that's still on the proxy.

@MahdiBaghbani
MahdiBaghbani force-pushed the refactor-ocm-http-transport-config branch from 8304ef7 to 590104c Compare September 30, 2026 13:38
@glpatcern
glpatcern force-pushed the refactor-ocm-http-transport-config branch from 590104c to b221c25 Compare October 1, 2026 06:30
@glpatcern
glpatcern force-pushed the refactor-ocm-http-transport-config branch from b221c25 to 6601082 Compare October 1, 2026 08:19
@glpatcern
glpatcern merged commit 6601082 into master Oct 1, 2026
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature OCM Open Cloud Mesh

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants