ferenc-csaky commented on PR #132:
URL: 
https://github.com/apache/flink-connector-pulsar/pull/132#issuecomment-6922710497

   Thanks for digging into the authorization path. I checked it against a 
4.0.14 broker with token auth and `PulsarAuthorizationProvider`: 
`getMessagesById` works with produce+consume and is denied with produce only, 
so you're right that tenant admin isn't needed.
   
   That doesn't change my view though. The calls FLINK-32938 removed were 
already consume or lookup level at the time. On 3.0.0, `getLastMessageId` and 
`getMessageIdByTimestamp` are PEEK_MESSAGES, `getSubscriptions` is 
GET_SUBSCRIPTIONS, `resetCursor` is RESET_CURSOR and 
`getPartitionedTopicMetadata` is GET_METADATA. So the decision wasn't about 
admin privileges. The ticket says the connector "should not access and interact 
with the admin endpoint", and that's still how I read it.
   
   While checking, I also ran the committer from this branch against the broker 
and found a few problems that I think block this regardless of the endpoint 
question:
   
   1. Message properties can override the transaction state. `TopicsImpl` puts 
the `X-Pulsar-txn-*` headers into the same map as the message's own properties, 
and the message properties are added after them 
([L1318-L1336](https://github.com/apache/pulsar/blob/v4.0.14/pulsar-client-admin/src/main/java/org/apache/pulsar/client/admin/internal/TopicsImpl.java#L1318-L1336),
 
[L1464-L1466](https://github.com/apache/pulsar/blob/v4.0.14/pulsar-client-admin/src/main/java/org/apache/pulsar/client/admin/internal/TopicsImpl.java#L1464-L1466),
 and 
[L1509](https://github.com/apache/pulsar/blob/v4.0.14/pulsar-client-admin/src/main/java/org/apache/pulsar/client/admin/internal/TopicsImpl.java#L1509)
 for batches). If the last record of a transaction has an 
`X-Pulsar-txn-uncommitted=false` property, the committer calls 
`signalAlreadyCommitted()` without committing, and the transaction is aborted 
at timeout together with all its records. With `X-Pulsar-txn-aborted=true` on 
an open transaction the committ
 er throws on every restore, so the job can't get past that checkpoint. In a 
batched entry the property doesn't even have to be on the last record. In SQL, 
`properties` is readable metadata on the source and writable on the sink, so in 
a pass-through job it's a producer on the upstream topic who decides this.
   
   2. It depends on broker behavior that is very new. The 
`X-Pulsar-txn-uncommitted` header doesn't exist on 3.0.0-3.0.5, 3.1.x and 
3.2.x. There the property is null, the committer ends up in the same 
`signalAlreadyCommitted()` branch, and no transaction with records is ever 
committed. On 3.0.6+, 3.3.x, 4.0.0-4.0.13, 4.1.x and 4.2.0-4.2.4 the header 
means `position > maxReadPosition`, so a committed transaction looks 
uncommitted while an earlier one on the same topic is still open. The re-commit 
then fails, and after `maxRecommitTimes` the job fails. The per-transaction 
meaning is only in 4.0.14 and 4.2.5 (apache/pulsar#26073). Our docs say 3.0.0 
or higher.
   
   3. Consume gives a lot more than read access. `PulsarAuthorizationProvider` 
maps UNSUBSCRIBE, SKIP, EXPIRE_MESSAGES and RESET_CURSOR to the same consume 
check as PEEK_MESSAGES 
([L708-L719](https://github.com/apache/pulsar/blob/v4.0.14/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/authorization/PulsarAuthorizationProvider.java#L708-L719)).
 With produce+consume, the sink's role could peek other producers' messages, 
skip another app's subscription backlog, reset its cursor, expire its messages 
and delete the subscription. Subscription-level permissions stop that, but 
somebody has to set them up. Existing exactly-once jobs with produce-only roles 
would also start failing after the upgrade (`retryLater`, then 
`FlinkRuntimeException` after 5 retries), so users would be forced to widen the 
permissions.
   
   4. The lookup isn't only used on recovery. `commit()` sends every V2 
committable through `commitCurrentTransaction()`, which calls admin before the 
first commit attempt, so every exactly-once checkpoint needs the HTTP endpoint 
to be reachable.
   
   <details>
   <summary>Repro for 1 (4.0.14 standalone, token auth, sink role with 
produce+consume)</summary>
   
   ```java
   Transaction txn = client.newTransaction().withTransactionTimeout(20, 
TimeUnit.SECONDS).build().get();
   producer.newMessage(txn).value("a").send();
   MessageId last = producer.newMessage(txn).value("b")
           .property("X-Pulsar-txn-uncommitted", "false")
           .send();
   
   // PulsarCommitter#commit with a V2 committable for (txn, last):
   //   -> signalAlreadyCommitted(), client.commit() is never called
   //   -> TC still reports the txn as OPEN; after 20s it's aborted and neither 
record is visible
   ```
   
   </details>
   
   IMO the proper fix belongs in Pulsar: the TC should be able to tell an 
already committed transaction from an aborted one over the binary protocol, 
e.g. by keeping the final state of ended transactions for a while. Then the 
connector doesn't need the admin endpoint for this. If you want to continue in 
this direction, I think it needs a dev@ thread first, since it reverts an 
earlier decision.
   
   So I'm still -1 on this.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to